简体   繁体   English

如何从另一个面板更新C#面板中图表的数据源

[英]how to update the datasource of a chart in C# panel from another panel

I'm creating an application consisting of 1 form and several panels, which I stack on top of another panel so I can just call the panel.BringToFront() to show it. 我正在创建一个由1个表单和几个面板组成的应用程序,它们堆叠在另一个面板的顶部,因此我可以调用panel.BringToFront()来显示它。

My first panel consists of a chart whose datasource is from my database. 我的第一个面板包含一个图表,该图表的数据源来自我的数据库。 So once I added or changed some data from my second panel, I need to update the chart in the first panel. 因此,一旦我在第二个面板中添加或更改了一些数据,就需要更新第一个面板中的图表。 What I've done is calling initializeChart() everytime I add or change something. 我所做的就是每次添加或更改某些东西时都调用initializeChart() The problem is my chart in the first panel is not updated. 问题是我的第一个面板中的图表未更新。 But when i try to update the table inside the same panel it works. 但是,当我尝试在同一面板内更新表时,它会起作用。 Here is my initializeChart() code : 这是我的initializeChart()代码:

private void initializeChart()
{               
    chart1.DataSource = database.getMonthlyProfitList();
    chart1.Series["Income"].XValueMember = "Bulan";
    chart1.Series["Income"].YValueMembers = "Pendapatan";
}

So do you guys have any Idea why I can update the view on the same panel but not on other panel, and if that's possible how to do that? 那么,你们有什么主意,为什么我可以在同一面板上而不是其他面板上更新视图,如果可以的话,该怎么做?

Add the following line of code in the last: 在最后添加以下代码行:

private void initializeChart()
{               
    chart1.DataSource = database.getMonthlyProfitList();
    chart1.Series["Income"].XValueMember = "Bulan";
    chart1.Series["Income"].YValueMembers = "Pendapatan";
    chart1.DataBind();
}

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

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