2 Attachment(s)
[RESOLVED] Is there an override/workaround for this?
The ms chart control is quite fussy. If I use this code in a loop where the data is created :
Code:
Form1.Chart1.Series(count).Points.AddXY(x, y)
*
It returns this, which is great.
Attachment 99177
However, I need the data to be in a datatable, and the chart to be created from the data in the table. Rather than using databind, because it gives terrible values for the axes, I tried this:
Code:
For Each row As DataRow In ARpassover_table.Rows
Chart1.Series(count).Points.AddXY(row.Item(0), row.Item(1))
Next row
The aim was to create the same chart as above. Unfortunately the result was this :
Attachment 99179
Whhhhhhhhyyyyyyyy! (The same data was used)
Any ideas on how to get it looking like the first example, using data from a datatable?
Re: Is there an override/workaround for this?
you can set the min, max values and label format for the x axis when it is data bound
Me.Chart1.ChartAreas(0).AxisX.Minimum = 0
Me.Chart1.ChartAreas(0).AxisX.Maximum = 30
Me.Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "#.#"
The chart is very flexible but getting to the proper properties can be a bit of a challenge
kevin
1 Attachment(s)
Re: Is there an override/workaround for this?
Thanks for quick reply,
No luck, for some reason, the X- axis becomes impervious to all simple editing using your examples resulted in this:
Attachment 99203
I believe that the X axis is showing the first 30 values of the datatable. I know that it works as expected with Y axis, but with the x axis it decides doing unhelpful stuff would be better
Re: Is there an override/workaround for this?
I set the format and scale on the x axis regularly with out issue.... I would put a break point of the chart.DataBind line and double check your variables before it runs just to make sure.
Unfortunately there is not a whole lot out there about ms chart. I had to learn most of what I know about it by trial and error.
GL
kevin
Re: Is there an override/workaround for this?
There is no chart.databind, this is all done by looping through a datatable using:
Code:
For Each row As DataRow In ARpassover_table.Rows
Chart1.Series(count).Points.AddXY(row.Item(0), row.Item(1))
Next row
2 Attachment(s)
Re: Is there an override/workaround for this?
o....
you should look into binding the table to the chart. It make life a bit easier and may be the root of your problem
To bind it set the Series.DataSource.XValueMember and YValueMember properties to the column names of datatable and call the chart.DataBind method...
Attachment 99207
Re: Is there an override/workaround for this?
Using databind warps the shape of the graph, because more of the data is in the 2nd half of the data. Look at the first post, i'm trying to recreate the first image, but using data that is already in a table
Re: Is there an override/workaround for this?
yea, sorry, I didn't read your first post correctly
Re: Is there an override/workaround for this?
All things being equal ...
Chart1.Series(count).Points.AddXY(x, y) & Chart1.Series(count).Points.AddXY(row.Item(0), row.Item(1))
... are exactly the same command. So, despite your protestations, all things clearly are not equal. When you say the data series are identical, is that actually true? Are they the exact same type, do they have the same precision, do both have the same starting point? If the data points are literally identical then there must be something in the set-up of the chart itself that is not identical in both cases. It simply cannot be the case that using values from a datatable is in itself the cause of the difference.
Re: Is there an override/workaround for this?
Yes, they are both identical. When I loop through the table trying to add them to the chart, the chart acts as if it is databound to the table. I don't really know why, but data binding causes all sorts of problems so I'm trying to avoid it. Without being databound, the graph looks like picture #1. When it's looped through the table to add, it behaves as if it is databound, and ruins the axes and the shape of the graph.
Re: Is there an override/workaround for this?
I still don't do Data, so I can't explain why the effect you are seeing happens, buuuut.....
When using your DataTable, try casting your data to the appropriate Type:
Code:
For Each row As DataRow In ARpassover_table.Rows
Dim x As Double = CDbl(row.Item(0))
Dim y As Double = CDbl(row.Item(1))
Chart1.Series(0).Points.AddXY(x, y)
Next row
Or maybe create a strongly Typed DataTable:
Code:
ARpassover_table = New DataTable
ARpassover_table.Columns.Add("X", GetType(Double))
ARpassover_table.Columns.Add("Y", GetType(Double))
'
' Fill table with data
'
and:
Code:
For Each row As DataRow In ARpassover_table.Rows
Chart1.Series(0).Points.AddXY(row.Item("X"), row.Item("Y"))
Next row
Maybe databinding to the Chart will work with a strongly Typed DataTable? I don't know; I don't do Data! :p
Re: Is there an override/workaround for this?
You... hero. I don't know why it works, but it does.
Casting the data to an appropriate type works exactly as I wanted it to, fantastic!