views:

551

answers:

1

Hi folks,

I've got a datatable with two columns "Status" (string) and "Total" (integer).

 Status       Total
 Success      34
 Missing      2
 Failed       10

I want to databind this into a pie chart with each Status per slice but I'm not sure what method of data binder is required?

Thanks, Jonesy

+1  A: 

Give this a shot:

    DataTable dt = new DataTable();
    dt.Columns.Add("Status");
    dt.Columns.Add("Total");

    dt.Rows.Add("Success", 34);
    dt.Rows.Add("Missing", 2);
    dt.Rows.Add("Failed", 10);

    Chart1.DataSource = dt;
    Chart1.Series["Series1"].XValueMember = "Status";
    Chart1.Series["Series1"].YValueMembers = "Total";
    Chart1.DataBind();

Update: The easiest way to add a legend is probably on the client side:

<Legends>
    <asp:Legend ... />
</Legends>

You can also add it programmatically:

    Chart1.Legends.Add("myLegend");
Chris Pebble
that worked a treat mate! thanks! One more thing if you would :) how do I add a legend to the chart?
iamjonesy
Updated the answer with information about legends.
Chris Pebble