我正在嘗試使用字典中的值創建Chart
,但是我的Chart
不顯示任何內容。我的代碼運行良好,沒有錯誤,我在表單上有一個圖表。圖表不會顯示數據點
我從來沒有在C#中創建圖表,所以我不知道我在做什麼。
這是我填寫它的代碼。
如果我刪除StatChart.update()
它會顯示項目在Dictionary
圖表上的總人數,但僅此而已
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();
}
}
}
}
您是否正在更新現有點? –