Hi i need to upload my data to the chart from my dataGridView as i load the form i well upload my data after that, the chart have to be created from my dataGridView this is my full code, i dont have problem with the DataGridStatisticFun() , i have aproblem with this function : DataGridToChart(),i am trying to be build the chart but the chart is empty..
private void StatisticForm_Load(object sender, EventArgs e)
{
//load my data to dataGridView
DataGridStatisticFun();
//the problem is in this function
DataGridToChart();
}
//create the chart
public void DataGridToChart()
{
chart1.Series.Clear();
ChartArea chartArea1 = new ChartArea();
chartArea1.AxisX.MajorGrid.LineColor = Color.LightGray;
chartArea1.AxisY.MajorGrid.LineColor = Color.LightGray;
chartArea1.AxisX.LabelStyle.Font = new Font("Consolas", 8);
chartArea1.AxisY.LabelStyle.Font = new Font("Consolas", 8);
chart1.ChartAreas.Add(chartArea1);
chart1.Series.Add("Series1");
chart1.Series[0] = new Series();
chart1.Series[0].XValueMember = dataGridViewStatistics.Columns[0].HeaderText;
chart1.Series[0].YValueMembers = dataGridViewStatistics.Columns[1].HeaderText;
chart1.DataSource = dataGridViewStatistics.DataSource;
chart1.Series[0].ChartType = SeriesChartType.Line;
}
public void DataGridStatisticFun()
{
int countProducts = dataB.Countstatistics();
Product[] products = new Product[countProducts];
products = dataB.Selectstatistics();
int j = 1, i = 0;
if (countProducts > 0)
{
countProducts = products.Count(s => s != null);
dataGridViewStatistics.RowCount = countProducts;
foreach (Product aProduct in products)
{
dataGridViewStatistics[0, i].Value = j++;
dataGridViewStatistics[1, i].Value = aProduct.Id;
dataGridViewStatistics[2, i].Value = aProduct.Name;
dataGridViewStatistics[3, i].Value = aProduct.Count;
i++;
}
}
}