Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C图表在for int循环中添加数据_C#_Wpf_Visual Studio 2012_Charts - Fatal编程技术网

C# C图表在for int循环中添加数据

C# C图表在for int循环中添加数据,c#,wpf,visual-studio-2012,charts,C#,Wpf,Visual Studio 2012,Charts,我需要这方面的帮助,我已经在wpf中创建了一个图表,在我的c中,我有以下内容: ((ColumnSeries)callLogs.Series[0]).ItemsSource = new KeyValuePair<string, int>[]{ for(int i=0; i<counter; i++) { new KeyValuePair<string, int>(callHour[i], callCounter[i])

我需要这方面的帮助,我已经在wpf中创建了一个图表,在我的c中,我有以下内容:

((ColumnSeries)callLogs.Series[0]).ItemsSource =
  new KeyValuePair<string, int>[]{

      for(int i=0; i<counter; i++)
      {
        new KeyValuePair<string, int>(callHour[i], callCounter[i])
      }
};
现在,上述说法不起作用

变量callHour和callCounter是从数据库中提取所需数据的数组,它们工作得很好,我只需要一种方法,通过数组中存储的值量将数据添加到图形中,如果这有意义的话

换句话说,不要使用这种方法:

((ColumnSeries)callLogs.Series[0]).ItemsSource =
  new KeyValuePair<string, int>[]{
    new KeyValuePair<string, int>(callHour[0], callCounter[0]),
    new KeyValuePair<string, int>(callHour[1], callCounter[1]),
    new KeyValuePair<string, int>(callHour[2], callCounter[2]),
    new KeyValuePair<string, int>(callHour[3], callCounter[3]),
    new KeyValuePair<string, int>(callHour[4], callCounter[4]),
    new KeyValuePair<string, int>(callHour[5], callCounter[5]),
    ...};

提前感谢

如果您尚未找到任何解决方案,请先创建KeyValuePair对象数组,然后将其分配给ItemSource:

 var items = new KeyValuePair<string, int>[counter];
        for(var i = 0; i < counter; i++)
        {
            items[i] = new KeyValuePair<string, int>(callHour[i], callCounter[i]);
        };
 (ColumnSeries)callLogs.Series[0]).ItemsSource = items;

您真的必须使用数组初始值设定项吗?只需先定义数组,然后使用for loop将值添加到数组中。是的,数组工作正常,我测试了输出。我这里的问题是,当我将for int循环放入时,图形不希望看到