I'm working on a chart in asp.net that is dinamically created from a DataTable. Basically I've got a DataTable like this:

DataTable

So, what I want in my chart is a column for each differente location, and for each diferent Type I want to have a "portion" of the column, meaning I would like to have a column per location divided per type.

I have managed to do something like this, but not quite what I would like: Chart

Now I'll try to explain my code.

First, i add the different locations in my datatable to a list of strings

string loc = "";
for (int i = 0; i < dtTipos.Rows.Count; i++)
{
    if (loc != dtTipos.Rows[i]["Location"].ToString())
        listaLocais.Add(dtTipos.Rows[i]["Location"].ToString());

    loc = dtTipos.Rows[i]["Location"].ToString();
}

After, for each different location, I select the rows to the corresponding location and create a series for each one of them. I proceed to create a point with y=0 and one with y=total

for (int i = 0; i < listaLocais.Count; i++)
{
    DataRow[] lRow = dtTipos.Select("Location = '" + listaLocais[i] + "'");
    foreach (DataRow dr in lRow)
    {
        string serie = dr["Location"].ToString().Substring(0, 2) + "_" + dr["Type"].ToString() + " - " + dr["Total"].ToString();
        Series s = new Series();
        s.Name = serie;
        s.Label = dr["Location"].ToString();
        s.ChartType = SeriesChartType.StackedColumn;
        chartTipo1.Series.Add(s);

        s.Points.AddXY(i + 1, 0);
        s.Points[0].Label = " ";
        s.Points.AddXY(i + 1,Convert.ToInt32(dr["Total"].ToString()));
        s.Points[1].Label = " ";// dtTipos.Rows[i]["Total"].ToString();
    }
}

The thing is: I think that because I create a serie for each row, everytime I use a diferent column, the y axis starts from where I left it.

Is there any way so I can get this to work? I'll appreciate any help.

Related posts

Recent Viewed