繁体   English   中英

如何将一个图表分配给另一C#

[英]How to assign one chart to another C#

我试图以其他窗口形式打开图表,但是用于图表中数据的类位于第一种形式。 我的目标是使图表能够在无模式窗口中多次打开。

在form1.cs中,我建立了图表:

Chart chart = new Chart();
Series price = new Series("Price"); //create new series
chart.Series.Add(price);

chart.Series["Price"].ChartType = SeriesChartType.Candlestick;

chart.Series["Price"]["OpenCloseStyle"] = "Candlestick";

chart.Series["Price"]["ShowOpenClose"] = "Both";


chart.Series["Price"]["PriceUpColor"] = "Green"; //Price increase = green
chart.Series["Price"]["PriceDownColor"] = "red"; //price decrease = red

for (int i = 0; i < data.Count; i++)
{
    chart.Series["Price"].Points.AddXY(data[i].getDate(), data[i].getHigh()); //Adds date and high value
    chart.Series["Price"].Points[i].YValues[1] = System.Convert.ToDouble(data[i].getLow()); //Low value added to chart
    chart.Series["Price"].Points[i].YValues[2] = System.Convert.ToDouble(data[i].getOpen()); //open value added to chart
    chart.Series["Price"].Points[i].YValues[3] = System.Convert.ToDouble(data[i].getClose()); //close value added to chart
}

Form2.cs:

public void DisplayChart(Chart newChart)
{
   chart1 = newChart;
   chart1.Show();
}

最好使Chart是一个单独的类,然后从所需的任何形式调用或创建它。 这遵循面向对象的原则,因此您可以重用代码并将其用于多个目的/视图。

暂无
暂无

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

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