locked
Multiple Series on Line Chart RRS feed

  • Question

  • I'm trying to add multiple series to one chart.  The data sets come from one table and span different sets of rows in the table. 

    For example one series will be all the data points where set_num = 1 and the other would be where set_num = 4

    I don't know what the actual numbers are until the page loads - I also don't know how many sets will need to be shown {anywhere from 1 - 10}

    Is there a way to simply do this?

    Right now I am databinding on page load but it results in the chart only showing the last set of data queried to the chart.
    Thursday, October 22, 2009 6:30 PM

Answers

  • So give this a whirl and see if it comes close to what you want. Notice that I am assuming that you're feeding the chart from a dataset, which you may or may not be doing.

    set_num = 1;
    Chart1.Series["Top"].Points.DataBind(ds.Tables[1].Select("SetNum='" + set_num + "'"), "Hours", "Voltage", "");

    set_num = 4;
    Chart1.Series["Top"].Points.DataBind(ds.Tables[1].Select("SetNum='" + set_num + "'"), "Hours", "Voltage", "");
    Please don't forget (and feel free to remind me) to post if you got the answer you wanted, and select who really answered your post when you do so future visitors will know too! Remember, this is .NET 4.0 in a .NET 3.5 world, you're a pioneer right now.
    Monday, October 26, 2009 5:49 PM

All replies

  • refer: http://weblogs.asp.net/ssnair/
    SSN "If you want to live a happy life, tie it to a goal. Not to people or things." : Albert Einstein
    Saturday, October 24, 2009 11:33 AM
  • That is not exactly what I was looking for since I want multiple series each from a different sql query on the same chart.
    Monday, October 26, 2009 2:32 PM
  • Can you provide a sample of data? I guess you're getting records like this in one returned resultset:
    ID  |  VALUE
    001 | 123
    001 | 134
    004 | 124
    004 | 145

    so if so, then you'll want to bind like this:
    Chart1.Series["Top"].Points.DataBind(record_source, "ID", "VALUE", "");

    where record_source could look like this:
    ds.Tables[0].AsDataView()
    or like this:
    List<item> i = new List<item>();
    Chart1.Series["Top"].Points.DataBind(i, "ID", "VALUE", "");
    Please don't forget (and feel free to remind me) to post if you got the answer you wanted, and select who really answered your post when you do so future visitors will know too! Remember, this is .NET 4.0 in a .NET 3.5 world, you're a pioneer right now.
    Monday, October 26, 2009 5:29 PM
  • My data would be like:

    Set Num |  Hours  |  Voltage | ...
    1  |  23.34  |  237.9
    1  |  33.34  |  198.2
    1  |  43.34  |  148.6
    1  |  53.34  |  118.1
    2  |  98.02  |  70.2
    2  |  103.02  |  103.8
    4  |  3.5  |  100.7
    4  |  10.5  |  120.2

    And I want to chart voltage vs hours for set_num 1 and set_num 4 as separate series.

    Thanks
    Monday, October 26, 2009 5:41 PM
  • So give this a whirl and see if it comes close to what you want. Notice that I am assuming that you're feeding the chart from a dataset, which you may or may not be doing.

    set_num = 1;
    Chart1.Series["Top"].Points.DataBind(ds.Tables[1].Select("SetNum='" + set_num + "'"), "Hours", "Voltage", "");

    set_num = 4;
    Chart1.Series["Top"].Points.DataBind(ds.Tables[1].Select("SetNum='" + set_num + "'"), "Hours", "Voltage", "");
    Please don't forget (and feel free to remind me) to post if you got the answer you wanted, and select who really answered your post when you do so future visitors will know too! Remember, this is .NET 4.0 in a .NET 3.5 world, you're a pioneer right now.
    Monday, October 26, 2009 5:49 PM
  • Use DataBindCrossTable option.
    • Proposed as answer by Prashant Goyal Friday, November 13, 2009 9:28 AM
    Friday, November 13, 2009 9:27 AM