Note: I am using .NET 6 that does not have a chart in Windows Form. I am using winforms-datavisualization.
I have a project that analyze text file on frequency of each letter and create Histogram with it. Problems accure when i am trying to draw the graph with sorted dictionary.
Using
chart1.Series.Add(series);
var keys = sortedFrequencies.Keys.ToList();
var values = sortedFrequencies.Values.ToList();
for (int i = 0; i < keys.Count; i++) {
int pointIndex = series.Points.AddXY(keys[i], values[i]);
series.Points[pointIndex].AxisLabel = keys[i].ToString();
textBox1.Text += keys[i].ToString();
textBox2.Text += values[i].ToString();
}
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
chart1.Invalidate();
I get all columns, but they are not sorted for some reason
And when i change var keys = sortedFrequencies.Keys.ToList();
to
var keys = sortedFrequencies.Keys.Select(k => k.ToString()).ToList();
I get what seems like sorted graph but all the columns overlaping