'WinForms Range Bar Chart Axis Not Rendering as Expected
I am attempting to generate a ranged bar chart using System.Windows.Forms.DataVisualization.Charting.SeriesChartType.RangeBar. When I add the x axis as integers it renders correctly as shown below:
int[] x = { 0, 0, 0, 1, 1, 1 };
int[] y = { 10, 2, 35, 1, 10, 20 };
int[] y2 = { 35, 4, 36, 2, 15, 40 };
var xValue = x.ToList();
var yValue1 = y.ToList();
var yValue2 = y2.ToList();
chart2.Series[0].Points.DataBindXY(x, y, y2);
However, when I swap the x axis integers to strings the chart does not render as above:
string[] x = { "Test", "Test", "Test", "Test1", "Test1", "Test1" };
int[] y = { 10, 2, 35, 1, 10, 20 };
int[] y2 = { 35, 4, 36, 2, 15, 40 };
var xValue = x.ToList();
var yValue1 = y.ToList();
var yValue2 = y2.ToList();
chart2.Series[0].XValueType =
System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
chart2.Series[0].Points.DataBindXY(x, y, y2);
Is there an elegant workaround to using string values for the x-axis while maintaining int or DateTime values for the y axis? Thanks in advance for your help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


