lundi 30 mars 2015

How to assign one chart to another C#

I'm attempting to open a chart in another window form, however the classes used for the data in the chart is in the first form. My goal here is to have a chart be able to open many times in a modeless window.


in form1.cs I build my chart:



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();
}

Aucun commentaire:

Enregistrer un commentaire