简体   繁体   English

如何在Asp.Net图表C#中创建图表系列数组对象

[英]How To Create Chart Series Array Objects in Asp.Net Charts C#

i want to create series dynamically for that i created series array objects like this 我想为此动态创建系列,就像这样创建系列数组对象

        Series[] series = new Series[10];

        series[0].Name = "Result Chart";

but while execution of program it showing object reference null error how to solve this problem 但是在执行程序时它显示对象引用为空错误如何解决此问题

Series[] series = new Series[10];
series[0] = new Series();// this line is the one you missed
series[0].Name = "Result Chart";
Series[] series = new Series[10];

This line create an array. 这行创建一个数组。 The new is just for creating array of series. 新的只是用于创建系列数组。

This line puts the value at the 0th index 这行将值放在第0个索引处

series[0].Name = "Result Chart";

The problem is that you have not instantiated the object at 0th index. 问题是您尚未实例化第0个索引的对象。 So you need to instantiated every index which you want to use. 因此,您需要实例化要使用的每个索引。
Like if you want to use the 0th index then you will have to use 就像您要使用第0个索引一样,则必须使用

series[0] = new Series();

or just create a loop to instantiated every index as follows 或只是创建一个循环以实例化每个索引,如下所示

for(int i=0;i<series.Count;i++)
{
   series[i] = new Series();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM