Good day!

Given: There is an InfoForBarChart class that provides Chart'у information for drawing histograms:

 internal class InfoForBarChart { public List<YData> Counts { get; private set; } public List<XData> IntervalTopBorders { get; private set; } public InfoForBarChart(List<YData> yData, List<XData> xData) { Counts = yData; IntervalTopBorders = xData; } } 

where the YData and XData classes are described as follows:

 internal class XData { public double TopBorderValue { get; set; } public XData(double topBorderValue) { TopBorderValue = topBorderValue; } } internal class YData { public int Count { get; set; } public YData(int count) { Count = count; } } 

Task: It is necessary to build a histogram, where the height of the columns would be determined from the Counts list of the InfoForBarChart class, and the values ​​for X - from the IntervalTopBorders list.

For now, I have the following drawing implementation:

 chart1.DataSource = infoForDrawingBarChart.Counts; // Источник данных - список Counts chart1.Series["CountsBar"].ChartType = SeriesChartType.Column; // Вертикальные столбцы chart1.Series.Clear(); // Удаляем все столбцы chart1.Series.Add("CountsBar").YValueMembers = "Count"; // Значение для каждого столбца берется из поля YData.Count chart1.Series["CountsBar"].YValueType = ChartValueType.Int32; chart1.DataBind(); 

The histogram after construction looks like this:

Barchart

What does not suit me: As can be seen from the figure, the histogram columns are numbered from 1 to 20 (20 is the number of items in the Counts list).

Question: Is it possible to somehow set the "numbering" of these columns, where the infoForDrawingBarChart.IntervalTopBorders list will be the data source for this numbering? If so, tell me how can I do this?

    1 answer 1

     myFirstChart.Series["Series1"].Points.AddXY(0, 0); 

    With this line you can set signatures (coordinates along OX and OY axes). That is, in the case of a histogram, the labels are on the horizontal axis and the vertical values. The first argument is the signature, the second is the value.