Same data plots overlapped for 2 different series, same dataset
Hi all,
Just getting into this product, so please be gentle ;-)
I have a chart control, with 2 series added. The data source for both series is the same, with three correctly populated columns - one for the X axis (date) and the other two for the series (Y values). I confirm the dataset (dsDash) contains the correct values.
When the chart is displayed, both series display the same data. I think I have hooked everything up OK. When I inspect the Rows property of the Series, they each have the same 3-valued rows, but it seems both series plot with only one of the fields (i.e. they plot the same, overlapping, data). I confirmed each row contains the three correct and different fields/values, and these match up to the dataset.
private void InitialiseChartDataDash()
{
chartControl1.Indexed = false;
modelDash = new ChartDataBindModel(dsDash, "RTReadings");
modelDash.XName = "DateTime";
modelDash.YNames = new String[] { "ImportWh", "ExportWh" }; // These match the fields in the datasource/model
ChartSeries seriesImp = new();
seriesImp.Name = "Import Wh";
seriesImp.Type = ChartSeriesType.Line;
seriesImp.Text = seriesImp.Name;
seriesImp.SeriesModel = modelDash;
ChartSeries seriesExp = new();
seriesExp.Name = "Export Wh";
seriesExp.Type = ChartSeriesType.Spline;
seriesExp.Text = seriesExp.Name;
seriesExp.SeriesModel = modelDash;
chartControl1.Series.Add(seriesImp);
chartControl1.Series.Add(seriesExp);
// X Axis
chartControl1.PrimaryXAxis.Title = "Date/Time";
chartControl1.PrimaryXAxis.ValueType = ChartValueType.DateTime;
chartControl1.PrimaryXAxis.DateTimeRange = new ChartDateTimeRange(DateTime.Today, DateTime.Now, 1, ChartDateTimeIntervalType.Auto);
// Y Axis
chartControl1.PrimaryYAxis.AutoSize = true;
chartControl1.PrimaryYAxis.ValueType = ChartValueType.Double;
Sorry for the in-line code. I can't find a code block thingy here :(
There seems to be some nuance I'm not picking up regarding how the series map to the datasource's fields. If anyone could share some light on this I would be most appreciative.
Cheers,
Mark.
SIGN IN To post a reply.
4 Replies
1 reply marked as answer
YP
Yuvaraj Palanisamy
Syncfusion Team
March 22, 2021 10:21 AM UTC
Hi Mark,
Greetings from Syncfusion.
We have analyzed your query and example code, we would like to inform you that the reported problem has been resolved by setting of separate ChartDataBindModel for each series. Please find the code example below.
CodeSnippet:
|
modelDash = new ChartDataBindModel(dsDash, "RTReadings");
modelDash.XName = "DateTime";
modelDash.YNames = new String[] { "ImportWh" };
modelDash_Export = new ChartDataBindModel(dsDash, "RTReadings");
modelDash_Export.XName = "DateTime";
modelDash_Export.YNames = new String[] { "ExportWh" };
ChartSeries seriesImp = new ();
seriesImp.Name = "Import Wh";
seriesImp.Type = ChartSeriesType.Line;
seriesImp.Text = seriesImp.Name;
seriesImp.SeriesModel = modelDash;
ChartSeries seriesExp = new ();
seriesExp.Name = "Export Wh";
seriesExp.Type = ChartSeriesType.Spline;
seriesExp.Text = seriesExp.Name;
seriesExp.SeriesModel = modelDash_Export;
chartControl1.Series.Add(seriesImp);
chartControl1.Series.Add(seriesExp);
|
Also, we have attached the sample for your reference, please find the sample from the below link.
Sample: https://www.syncfusion.com/downloads/support/forum/163733/ze/WindowsFormsApplication61473703999
Please let us know if you have any concern.
Regards,
Yuvaraj.
MA
Mark
March 22, 2021 10:44 AM UTC
After some more searching and thinking I finally worked it out.
I mistakenly thought I only needed 1 model, and could have 2 or more series from it, each series being one of the columns (fields).
Such as:
Date, Import, Export
1/1/21, 0, 10
2/1/21, 0 15
3/1/21, 5, 0
etc.
From trawling through the samples I worked out that each series needs it's own model, with each model using the same DataSet table, just bound to different fields via the "YNames" property. I thought the YNames property (list of strings) was a list of fields the data would need to come from.
So it ended up looking like this:
// 1st Model and Series
var modelImport = new ChartDataBindModel(dsDash, "RTReadings"); // dataset and the table to use
modelImp.XName = "DateTime";
modelImp.YNames = new String[] { "ImportWh" }; // the field to use for the y-value
ChartSeries seriesImp = new();
seriesImp.SeriesModel = modelImport;
seriesImp.Name = "Import Wh";
seriesImp.Type = ChartSeriesType.Area;
seriesImp.Text = seriesImp.Name;
// 2nd Model and Series
var modelExport = new ChartDataBindModel(dsDash, "RTReadings"); // Same dataset, same table
modelExport.XName = "DateTime";
modelExport.YNames = new String[] { "ExportWh" }; // different field
ChartSeries seriesExp = new();
seriesExp.SeriesModel = modelExport;
seriesExp.Name = "Export Wh";
seriesExp.Type = ChartSeriesType.Area;
seriesExp.Text = seriesExp.Name;
chartControl1.Series.Add(seriesImp);
chartControl1.Series.Add(seriesExp);
I hope this helps any newbie like me :-)
Cheers,
Mark.
Marked as answer
MA
Mark
March 22, 2021 10:48 AM UTC
Thanks for your Answer Yuvaraj!
I think you answered while I was getting ready to hit send. Anyway, it is nice to have what I worked out to be confirmed by a pro!
Thanks again.
Cheers,
Mark.
YP
Yuvaraj Palanisamy
Syncfusion Team
March 23, 2021 05:43 AM UTC
Thank you for your update. We are glad to know that the solution works at your end.
Regards,
Yuvaraj
SIGN IN To post a reply.