Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2060
Composite Chart with Date range
posted

Hi,

I've got to produce a chart that shows how many contacts have been added or deleted from the database over a six month period.

I was hoping to show a chart with an Y axis going from a negative number to a positive number with the X axis running from the 0 value on the Y axis.  The Y axis would be the number of contacts and the X axis would be dates.

The positive would show the contacts added and the negative the contacts deleted.  

I thought I need to add a Series for the Added and a Series for the Deleted.

Here's a mock up

I've been trying to get this to work all afternoon using various examples but I'm failing miserably.

I initially tried binding the series to a List(Of ) but that failed so  I converted it to a table.  It seems to see the data to set some labels but doesn't show anything in the graph.

I've no idea what to try next so any help pointing me in the right direction would be greatly appreciated

Here's my code for setting up the axis, data and chart.  All it's trying to do at the moment is display the Added contacts.

Private Sub SetupContactsVEventschart()

Dim posContacts As New List(Of ContactVEventsContactChartData)
posContacts.Add(New ContactVEventsContactChartData With {.Label = "Added", .Count = 2, .ActivityDate = Date.Parse("20 Jul 2014")})
posContacts.Add(New ContactVEventsContactChartData With {.Label = "Added", .Count = 0, .ActivityDate = Date.Parse("21 Jul 2014")})
posContacts.Add(New ContactVEventsContactChartData With {.Label = "Added", .Count = 3, .ActivityDate = Date.Parse("22 Jul 2014")})
posContacts.Add(New ContactVEventsContactChartData With {.Label = "Added", .Count = 5, .ActivityDate = Date.Parse("24 Jul 2014")})

ContactsVEventsUltraChart.ChartType = ChartType.Composite

Dim area As New ChartArea
ContactsVEventsUltraChart.CompositeChart.ChartAreas.Add(area)

Dim axisX As New AxisItem()
axisX.OrientationType = AxisNumber.X_Axis
axisX.DataType = AxisDataType.Time
'axisX.SetLabelAxisType = SetLabelAxisType.DateData
axisX.Labels.ItemFormatString = ""
axisX.Labels.Orientation = TextOrientation.VerticalLeftFacing
axisX.TimeAxisStyle.TimeAxisStyle = RulerGenre.Discrete

Dim axisY As New AxisItem()
axisY.OrientationType = AxisNumber.Y_Axis
axisY.DataType = AxisDataType.Numeric
axisY.Labels.ItemFormatString = ""
axisY.RangeType = AxisRangeType.Custom
axisY.RangeMin = -50
axisY.RangeMax = 50


area.Axes.Add(axisX)
area.Axes.Add(axisY)


Dim table As DataTable = GetContactData(posContacts)

Dim series1 As New NumericTimeSeries()
series1.Label = "Added"
series1.Data.DataSource = table
series1.Data.TimeValueColumn = "ActivityDate"
series1.Data.ValueColumn = "Count"


Me.ContactsVEventsUltraChart.CompositeChart.Series.Add(series1)


Dim myColumnLayer As New ChartLayerAppearance()
myColumnLayer.ChartType = ChartType.ColumnChart
myColumnLayer.ChartArea = area
myColumnLayer.AxisX = axisX
myColumnLayer.AxisY = axisY
myColumnLayer.Series.Add(series1)
Me.ContactsVEventsUltraChart.CompositeChart.ChartLayers.Add(myColumnLayer)

End Sub

Private Shared Function GetContactData(ByVal items As List(Of ContactVEventsContactChartData)) As DataTable
Dim table As New DataTable()
table.Columns.Add("Label", GetType(String))
table.Columns.Add("Count", GetType(Integer))
table.Columns.Add("ActivityDate", GetType(DateTime))
For Each i In items
table.Rows.Add(New Object() {i.Label, i.Count, i.ActivityDate})
Next
Return table
End Function

Kind regards,

Nathan

Parents Reply Children