Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Has anyone else noticed in Visual Studios's (I'm using 2012) chart control doesn't place the data point correctly on the chart if you have a single point and the XValue is 0, it places it at 1 instead?

example code:

Chart1.Series.Clear();
Chart1.Series.Add(new Series());
Chart1.Series[0].ChartType = SeriesChartType.Point;

Chart1.Series[0].Points.AddXY(0,0);


If you run that code it will place a data point at (1,0). As soon as a second point is added, it will correctly graph the point at (0,0). If instead the data point was added at XValue = 0.001, instead of XValue=0, it would graph correctly as well.

Has anyone else seen this? Is there a solution to this problem?
Posted
Updated 2-Sep-14 12:05pm
v2

1 solution

This depends on the .NET version (please update the tag for reference). In .NET 4.5, you have a property IsXAxisQuantitative on the Series that you can set to 'true' to prevent this behavior:
C#
Chart1.Series[0]["IsXAxisQuantitive"] = true;

or
C#
Chart1.Series[0].CustomProperties = "IsXAxisQuantitative=True";

In older versions of .NET, you could add a transparant dummy point at x != 0:
C#
DataPoint dummyPoint = new DataPoint(1, 0);
dummyPoint.Color = Color.Transparent;
Chart1.Series[0].Points.Add(dummyPoint);
 
Share this answer
 
v3
Comments
MrGlass3 2-Sep-14 18:08pm    
I'm using .NET 4.5.1, sorry for not included that. However, there is no IsXAxisQuantitive field within the series object which I can see.
kbrandwijk 2-Sep-14 18:42pm    
It's a custom property, so it is only accessible by indexer (I think) or by using the CustomProperties property. I don't have VS available right now, but one of the two (or both) should work.
MrGlass3 3-Sep-14 10:44am    
I tried looking into CustomProperties and I found a list of indexers, I don't understand why they created them this way? Why not just have a Boolean field 'IsXAxisQuantitative'? Any idea why they went this route?
kbrandwijk 3-Sep-14 11:00am    
Because the Custom Properties available on, for example, a Serie or a DataPoint, depend on the Chart type chosen and other related settings. Not all custom properties are relevant in every context, so that's why they decided to implement them like this, instead of creating 'real' properties for every possible custom property in every possible scenario. There are around 100 of them, if I'm not mistaken.
MrGlass3 3-Sep-14 11:45am    
That makes complete sense actually. Thanks again!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900