0
I have in my project a Gridview where I manually insert data in the last column (index 7) and a Piechart that must be updated according to this last column, however, as much as I can get the data from the column I cannot pass them to the Chart. Follow code where I capture the valuables:
TimeSpan[] permanencia = new TimeSpan[dataGridView1.Rows.Count];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
permanencia[i] = TimeSpan.Parse(Convert.ToString(dataGridView1.Rows[i].Cells[7].Value));
}
So far so good, but when I try to pass the data to update my Chart, nothing happens. Follow code:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
ds = new DataSet(Convert.ToString(permanencia[i]));
chart1.DataSource = ds;
chart1.DataBind();
chart1.Update();
}
Could someone help me? I’m a beginner with Charts...
Note: I am working with Windowsform and as already said, the data of this column is generated manually...
On request, follow the code to fill in the last column, to UNIQUE filled in this way...
// CALCULO DA PERMANÊNCIA E INSERÇÃO DA COLUNA COM OS RESPECTIVOS DADOS
DateTime ent = new DateTime();
DateTime sad = new DateTime();
TimeSpan permanencia = new TimeSpan();
DataGridViewRow l = dataGridView1.Rows[0];
DataGridViewCell c = l.Cells[0];
dataGridView1.Columns.Add("colunaPermanencia", "Permanencia");
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
ent = Convert.ToDateTime(dataGridView1.Rows[i].Cells[4].Value);
sad = Convert.ToDateTime(dataGridView1.Rows[i].Cells[6].Value);
permanencia = sad - ent;
dataGridView1.Rows[i].Cells["colunaPermanencia"].Value = permanencia.ToString();
}
For a Chart, you have to enter row data...columns... X,Y,Z axes anyway, multiple data... this command ds = new Dataset(Convert.Tostring(permanence[i])); I don’t think it will even work
– Rovann Linhalis
show how you fill all the gridview
– Rovann Linhalis
Ready. I edited the question with the code
– DLopes
I was referring to how you fill in all gridview data, all columns
– Rovann Linhalis
and what data should appear on the Chart ? time of stay and more ?
– Rovann Linhalis
I’m using Mysql connection and pulling the other data from there. Only this column is different
– DLopes
Residence time and name of the course
– DLopes
uses a Dataset/ Datatable coming from mysql ?
– Rovann Linhalis