I am using the Chart control for a Winforms app. I am loading the control with two data series - each with its own datatable.
Here is my code for the control (chrtCharts):
ChartDataBindModel modelBooking = null;
ChartDataBindModel modelInvoicing = null;
ChartDataBindAxisLabelModel xAxisModel = null;
modelBooking = new ChartDataBindModel(dtBooking);
modelBooking.XIndex = 0;
modelBooking.YIndexes = new int[] { 1 };
modelInvoicing = new ChartDataBindModel(dtInvoicing);
modelInvoicing.XIndex = 0;
modelInvoicing.YIndexes = new int[] { 1 };
ChartSeries seriesBookings = new ChartSeries("BOOKINGS");
seriesBookings.Text = seriesBookings.Name;
seriesBookings.SeriesModel = modelBooking;
seriesBookings.Type = ChartSeriesType.Column;
seriesBookings.Style.DisplayText = true;
chrtCharts.Series.Add(seriesBookings);
ChartSeries seriesRevenue = new ChartSeries("REVENUE");
seriesRevenue.Text = seriesRevenue.Name;
seriesRevenue.SeriesModel = modelInvoicing;
seriesRevenue.Type = ChartSeriesType.Column;
seriesRevenue.Style.DisplayText = true;
chrtCharts.Series.Add(seriesRevenue);
xAxisModel = new ChartDataBindAxisLabelModel(dtBooking);
//xAxisModel.PositionName = "DATES";
//xAxisModel.PositionIndex = 0;
xAxisModel.LabelName = "DATES";
//xAxisModel.LabelIndex = 0;
chrtCharts.PrimaryXAxis.LabelsImpl = xAxisModel;
chrtCharts.PrimaryXAxis.CustomLabelsParameter = ChartCustomLabelsParameter.Position;
chrtCharts.PrimaryXAxis.HidePartialLabels = true;
chrtCharts.PrimaryXAxis.ValueType = ChartValueType.Custom;
chrtCharts.PrimaryXAxis.Range = new MinMaxInfo(0, dtBooking.Rows.Count + 1, 1);
chrtCharts.PrimaryXAxis.PointOffset = 1;
chrtCharts.PrimaryXAxis.LabelAlignment = StringAlignment.Center;
chrtCharts.PrimaryXAxis.LabelRotate = true;
chrtCharts.PrimaryXAxis.LabelRotateAngle = 70;
chrtCharts.PrimaryXAxis.Title = "";
chrtCharts.PrimaryYAxis.ValueType = ChartValueType.Double;
chrtCharts.PrimaryYAxis.Format = "C";
chrtCharts.PrimaryYAxis.Title = "";
chrtCharts.ShowLegend = true;
chrtCharts.LegendsPlacement = ChartPlacement.Inside;
chrtCharts.LegendPosition = ChartDock.Top;
chrtCharts.AutoHighlight = false;
chrtCharts.SeriesHighlight = false;
chrtCharts.Refresh();
chrtCharts.Visible = true;
However, the chart displays as this:
* Please note that the X-Axis labels are all correct, but the data is all plotted on top of itself.
If I change the line of code:
chrtCharts.PrimaryXAxis.ValueType = ChartValueType.Custom;
to:
chrtCharts.PrimaryXAxis.ValueType = ChartValueType.Catagory;
then I get the following chart:
* Note that now the X-Axis labels are not correct, but the data is plotted correctly (out of order, but not on top of itself.)
How can I get the data to be displayed correctly with the correct X-Axis labels?
Thanks,
Greg
Hi Greg,
We will check and update you with complete details on June 06, 2022.
Regards,
Yuvaraj.
Hi Greg,
We still need some more time and will update details on or before June 8, 2020. We appreciate your patience until then.
Regards,
Devakumar D
Hi Greg,
We can resolve the reported problem by removing the XIndex set as “0” for both modelBooking and modelInvoicing ChartDataBindModel as per in the below code example.
|
… modelBooking = new ChartDataBindModel(dtBooking);
modelBooking.YIndexes = new int[] { 1 }; modelInvoicing = new ChartDataBindModel(dtInvoicing);
modelInvoicing.YIndexes = new int[] { 1 }; |
Output:
Please find the example sample from the attachment below and let us know if you need any further assistance on this.
Regards,
Devakumar D
Thank you very much!!
Hi Greg,
Thanks for your update.
Please let us know if you need any further assistance.
Regards,
Devakumar D