There are different ways about how the data of a Infragistics Linechart can be initialized. However, I would like to use its Property 'DataSource' and format the data before, since I already use this for other charts too.
So I would prefer this way:
UltraChart1.DataSource = myDataSource
Against this (Whole example with NumericTimeSeries is here)
Dim series1 As New NumericTimeSeries series1.Label = "Series1" series1.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-4), 12346, "Januar", True)) series1.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-3), 10000, "Februar", True)) series1.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-2), 14000, "März", True)) series1.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-1), 18000, "April", True)) series1.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(10), 800, "Mai", True)) Dim series2 As New NumericTimeSeries series2.Label = "Series2" series2.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-8), 500, "Januar", True)) series2.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-6), 350, "Februar", True)) series2.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-4), 600, "März", True)) series2.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(-2), 800, "April", True)) series2.Points.Add(New NumericTimeDataPoint(DateTime.Now.AddMonths(10), 800, "Mai", True)) UltraChart1.Series.Add(series1) UltraChart1.Series.Add(series2)
However, my question is of how to format the DataSource, that it actually shows up more than one series.
No matter what I try, I'm only getting one Series in the Linechart.
The result should look something like this
We are using an abstract of a datatable, which works fine for the other ChartTypes (PieChart, BarChart, etc.). A good example of how to achieve this, would really be appreciated.
Hello Fabian,
There are different approaches to solve this task. Here are few possible options:
Option 1: You could create a one or more series and bind each of them using the code:
series2 = new NumericSeries();
series2.DataBind(dt,"2008", "Month");
series2.Label ="Year 2008";
series2.PEs.Add(new PaintElement(Color.Blue));
myColumnLayer.Series.Add(series2);
ultraChart1.CompositeChart.Series.Add(series2);
Option 2:
series3 =new NumericSeries();
series3.Data.DataSource = dt;
series3.Data.ValueColumn ="2009";
series3.Data.LabelColumn ="Month";
series3.Label ="Year 2009";
series3.PEs.Add(new PaintElement(Color.Yellow));
myColumnLayer.Series.Add(series3);
ultraChart1.CompositeChart.Series.Add(series3);
For more details, please take a look at the first attached sample where I`m using different series in a composite chart.
Option 3:
If you want to use direct DataSource property , you should specify the data type of your columns. Please take a look at the second sample for more details.
Let me know if you have any questions.
Regards
Hello GeorgiThank you very much for your answer. It helped me a lot!Is there also a way to have more than one point per month in LineCharts? E.g. to show the trend in January?Regards
Thank you, that helped me a lot.
Thanks for the feedback. Let me know if you have any further questions.
Hello Georgi,
Is it possible to add toggling of series/lines as you did in the CompositeChart.zip example when binding straight to a datatable without explicitly creating series?
For example:
DataTable dt = new DataTable();dt.Columns.Add(New DataColumn("DateField", typeof(System.DateTime)));dt.Columns.Add(New DataColumn("SeriesField1", typeof(System.Decimal)));dt.Columns.Add(New DataColumn("SeriesField2", typeof(System.Decimal))); ...Add data rows to table//ultraChart1 is a LineChart ultraChart1.DataSource = dt;ultraChart1.DataBind();I'd like to be able to do something like the treeview in your sample to hide the line that corresponds to a particular SeriesFieldX column. Is there a way to do that without explicitly creating the NumericSeries in code and using them? When I look at the UltraChart in debug there are 0 series so I don't see how.
Thanks in advance for your assistance!
Hello Fred,
Yes, It is possible. I create a new sample for you. Please take a look at the attached sample and if you have any questions, feel free to write me
Thank you very much for taking the time and for being so quick Georgi! That sample was perfect to get me on the right track.