簡體   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