I’m creating a Chart using the .net 4.0 System.Web.UI.DataVisualisation library and have noticed an odd behaviour.
First I’m creating a Series with two datapoints, each with the same value on the X-axis, as follows:
Dim series As New Series()
series.Points.Add(New DataPoint(0, 10))
series.Points.Add(New DataPoint(0, 15))
'.. add to chart and render
When I render this chart in the browser, I get two points on the X-axis, both with the same label.
However, when I add another datapoint, on a different value on the x-axis, as follows:
Dim series As New Series()
series.Points.Add(New DataPoint(0, 10))
series.Points.Add(New DataPoint(0, 15))
series.Points.Add(New DataPoint(1, 14))
'.. add to chart and render
Then, the chart still only renders two points on the X-axis (0 and 1), and the first two values (on x-Axis value 0) are connected vertically!
Anyone know why this behaviour is different? Either behaviour would be acceptable really, but I’d like to be able to choose one of them…
thanks!
Sam
If you enter 0 as the x-value of your datapoint, the Series will calculate it for you. So if you create a chart with all x-values as 0, the Series will interpret this as ‘the x-value is not important, I will render all items as seperate values on the x-axis’. But as soon as you add an x-value that is not 0, the series starts using the x-values you supplied.
This is brilliantly described on msdn as:
To fix your problem, you have to define the first series as this:
This will render your datapoints correctly.