图表将不显示数据点 [英] Chart will not display DataPoints
本文介绍了图表将不显示数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用字典中的值制作图表
,但是我的图表
不显示任何内容。我的代码运行良好,没有错误,并且我在表单上有一个图表。
I am trying to make a Chart
using the values from a dictionary however my Chart
doesn't display anything. My code runs fine with no errors and I have a chart on a form.
我以前从未在C#中制作图表,所以我不知道自己在做什么。
I have never made a chart in C# before so I have no clue what I am doing.
这是我填写的代码。
如果我删除了 StatChart.update ()
,它将在图表上的词典
中显示项目总数,仅此而已
If I remove StatChart.update()
it will display the total number of items in the Dictionary
on the chart but that is all
private void FillStatChart(Dictionary<string, int> dictionary)
{
int dicLength = dictionary.Count;
StatChart.Series.Clear();
StatChart.Series.Add("Occurences");
foreach (System.Windows.Forms.DataVisualization.Charting.DataPoint point in StatChart.Series["Occurences"].Points)
{
foreach (KeyValuePair<string, int> pair in dictionary)
{
for (int idx = 0; idx < dicLength; idx++)
{
point.SetValueXY(idx, pair.Value);
StatChart.Update();
}
}
}
}
推荐答案
您需要将新的
DataPoints
添加到点
集合。
更改此:
foreach (System.Windows.Forms.DataVisualization.Charting.DataPoint point in StatChart.Series["Occurences"].Points)
{
foreach (KeyValuePair<string, int> pair in dictionary)
{
for (int idx = 0; idx < dicLength; idx++)
{
point.SetValueXY(idx, pair.Value);
StatChart.Update();
}
}
}
为此:
Series S = StatChart.Series["Occurences"];
for (int idx = 0; idx < dicLength; idx++)
{
KeyValuePair<string, int> pair = dictionary.ElementAt(idx);
S.Points.AddXY(idx, pair.Value);
S.Points[idx].ToolTip = pair.Key; // optional tooltip
}
SetValueXY
仅用于稍后更改
SetValueXY
is only for changing the values of a DataPoint
later.
这篇关于图表将不显示数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文