我正在尝试以另一种窗口形式打开图表,但是用于图表中数据的类是第一种形式。我的目标是让图表能够在无模式窗口中多次打开。
在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();
}
答案 0 :(得分:0)
最好使图表是一个单独的类,并根据您需要的任何形式调用或创建它。 这遵循面向对象的原则,因此您可以重用代码并将其用于多个目的/视图。