1

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

iamjonesy
  • 24,732
  • 40
  • 139
  • 206

2 Answers2

7

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 Van Opstal
  • 36,423
  • 9
  • 73
  • 90
3

I've did some research today and found this article as the best one.

Here's C# code above (by Chris) translated to VB.NET

Enjoy!

Dim dt As 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()
Herb Meehan
  • 177
  • 1
  • 11