您好, 我刚创建了一个图形图表,代码与OlrDb访问基础一起运行并且运行良好。
Chart Graph_121 = new Chart(); // CréerunChart vide ChartArea ChartArea121 = new ChartArea(); // ChartArea(zone graphique) Graph_121.ChartAreas.Add(ChartArea121); // Ajoute le ChartAreaàlaCollection ChartAreas du Chart Series series121 = new Series(); // Créationserie(qui contiendront les DataPoints)我的问题如下: 在同一表格中我想添加一个按钮并删除方法清除我的图表,该怎么办? 什么都行不通:
Graph_121.Clear() ; ChartArea121.Clear(); series121.Clear();当前上下文中不存在名称Graph_121! 我们可以公开声明Graph_121,ChartArea121,series121吗? br $> b $ b 谢谢 我的尝试:
Control Page_Principale = Graph_121.Page_Principale; Page_Principale.Controls.Remove(Graph_121); Graph_121.Clear(); ChartArea121.Clear(); series121.Clear();解决方案
如果你通过代码创建它,看起来你的图表将超出范围以上。 将您的图表在班级定义为私人或公共成员,以便您的程序的不同部分可以看到图表,而不仅仅是首先创建图表的方法(作为本地变量)。
您好,感谢您的帮助。我刚刚创建了一个这样的方法:
public void MyGraph_121() { string CentreAnnee = Filtre_Cbo_Annee.Text; Chart Graph_121 = new Chart(); ChartArea ChartArea121 = new ChartArea(); Graph_121.ChartAreas.Add(ChartArea121); 系列series121 = new 系列 { IsValueShownAsLabel = true , ChartArea = ChartArea1 }; Graph_121.Series.Add(series121); // 其余代码 }
然后我在页面顶部说:
public int i1,i2,i3,i4,i5,i6,i7 ,i8,i9,i10,i11,i12,i13,i14; public string CentreAnnee; public ChartAreaCollection Graph_121,ChartArea121,series121;
然后一旦显示的图表我用这个按钮测试:
private void button1_Click( object sender,EventArgs e) { ChartArea121.Clear( ); series121.Clear(); ChartArea121.Clear(); }
我收到一条错误消息:
System.NullReferenceException: ' 对象引用未设置为对象的实例。' ChartArea121 null 。
如何申报图表项?
public ChartAreaCollection Graph_121,ChartArea121,series121;
它是对象,字符串不会,int也是? 谢谢
Hello, I just created a Graphics Chart by code that works with an OlrDb access base and works well.
Chart Graph_121 = new Chart(); // Créer un Chart vide ChartArea ChartArea121 = new ChartArea(); // ChartArea (zone graphique) Graph_121.ChartAreas.Add(ChartArea121); // Ajoute le Chart Area à la Collection ChartAreas du Chart Series series121 = new Series(); // Création serie (qui contiendront les DataPoints)My question is the following : In the same form I want to add a button and delete with the method Clear my Chart, how to do? Nothing works :
Graph_121.Clear(); ChartArea121.Clear(); series121.Clear();The name Graph_121 does not exist in the current context ! Can we declare Graph_121, ChartArea121, series121 in public? thank you What I have tried:
Control Page_Principale = Graph_121.Page_Principale; Page_Principale.Controls.Remove(Graph_121); Graph_121.Clear(); ChartArea121.Clear(); series121.Clear(); 解决方案 Looks like your "chart" is going "out of scope" if you created it "by code" as above. Define your chart "at the class level" as a "private or public" member so that different parts of your program can "see" chart and not just the method that first created chart (as a "local" variable).Hello, Thanks for your help. I just created a method like this:public void MyGraph_121() { string CentreAnnee = Filtre_Cbo_Annee.Text; Chart Graph_121 = new Chart(); ChartArea ChartArea121 = new ChartArea(); Graph_121.ChartAreas.Add(ChartArea121); Series series121 = new Series { IsValueShownAsLabel = true, ChartArea = "ChartArea1" }; Graph_121.Series.Add(series121); // rest of the code }
Then I said at the top of my page like this:
public int i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14; public string CentreAnnee; public ChartAreaCollection Graph_121, ChartArea121, series121;
Then once the graph displayed I test with this button:
private void button1_Click(object sender, EventArgs e) { ChartArea121.Clear(); series121.Clear(); ChartArea121.Clear(); }
I have as an error message:
System.NullReferenceException : 'Object reference not set to an instance of an object.' ChartArea121 was null.
How to declare Chart items?
public ChartAreaCollection Graph_121, ChartArea121, series121;
Is it objects, string does not go, int either? thank you
更多推荐
C#visualstudion windows形成图形图表
发布评论