.NET Framework Developer Center >
.NET Development Forums
>
Chart Controls for .NET Framework
>
using DataView with asp.net Chart control
using DataView with asp.net Chart control
- How can i use this table below to plug a pie chat?
state SumPostVoice SumPostData SumPreVoice SumPreData National 324 42 9 2
My DataView is
DataView PieDv = PieTable.DefaultView;
Chart2.Series[
"Default"].Points.DataBindXY(PieDv, "State", PieDv, "SumPostVoice");
Chart2.Series[
"Default"].Points.DataBindXY(PieDv, "State", PieDv, "SumPostData");
Chart2.Series[
"Default"].Points.DataBindXY(PieDv, "State", PieDv, "SumPreVoice");
Chart2.Series[
"Default"].Points.DataBindXY(PieDv, "State", PieDv, "SumPreData");
When i load my chart i just get one big round doughnut color and its just says national.
I taught it was going to divide it into 100%.
Thanks in Advance
Answers
- The legends take binding from supplied table's column name also, if you don't know.
Try something like below :
SomeChart.Series[0].Legend = PieTable.Columns[0].ColumnName;
If you find solution from my answer, please mark it as answer.- Marked As Answer byAlex GorevMSFT, OwnerThursday, November 19, 2009 5:36 AM
All Replies
- Normally you would use the values in a single column
If you want to use the values in 1 row, you have to iterate through all the column values
Dim dtTest As New DataTable Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dtTest.Columns.Add("State", GetType(String)) dtTest.Columns.Add("Sum_Post_Voice", GetType(Integer)) dtTest.Columns.Add("Sum_Post_Data", GetType(Integer)) dtTest.Columns.Add("Sum_Pre_Voice", GetType(Integer)) dtTest.Columns.Add("Sum_Pre_Data", GetType(Integer)) DataGridView1.DataSource = dtTest.DefaultView dtTest.Rows.Add("National", 324, 42, 9, 2) End Sub Private Sub btnGraph_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGraph.Click Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Doughnut Chart1.Series(0).IsValueShownAsLabel = True For i As Integer = 1 To dtTest.Columns.Count - 1 Chart1.Series(0).Points.AddY(dtTest.Rows(0).Item(i)) Next End Sub
- Proposed As Answer byHammerGuy Friday, November 06, 2009 6:57 AM
- Thanks Jwavila,
But i would also need the x axis which is the column name.
How can i get that?
Thx in Advance - I'm sorry, can you explain why you need two axis to draw a circle. Last time I checked a pie chart only had one real dimension.
For the purists who can't wait to chime in, yeah, I know any graph takes up space in two dimensions, but we're talking about the data to fuel the chart itself, yeah?
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. - Cole thanks for the trply.
Yeah you are right about needing only one axis.
Sorry what i want is to show the label text on the pie chat.
Right now i can see the pie chart divided and all good but i want label text.
How can i get the columns in my data as above to show as a label.
If not can i hardcode it e.g like so
string[] xValues = { "SumPostVoice", "SumPostData", "SumPreVoice", "SumPreData" };
Hope you understand me now and thks in Advance - Hi
I think he means that he wants to have the column name in the description of the pie chart. just check into more details of the ms chart i never worked with ms charts but i have used devexpress charts and in that we had a wizard through which you could do it easily. I think u will be able to find it if u digg a little deeper.
Wish you luck
HG - Thanks hammer thats exactly what i want.
Cole,hammer
i noticed i can use the
Chart2.Series["Default"].Label = "#VAL{#}";
to add the label to display on the pie chart
But this is where i have the proble with the legend text
Chart2.Series["Default"].LegendText = "#AXISLABEL";
when i use the above the legend shows 324, 42, 9, 2
I need a text for the legend unless it looks funny.
How can i get the column names or even hardcode the values dynamically
My code below:
for (int i = 0; i <= PieTable.Columns.Count - 1; i++)
{
Chart2.Series["Default"].Points.AddY(PieTable.Rows[0].ItemArray[i]);
Chart2.Series["Default"].LegendText = "#AXISLABEL";
Chart2.Series["Default"].Label = "#VAL{#}";
//How can i get the column names
}
Sure i tried doing :
foreach (DataColumn column in PieTable.Columns)
But no cigar.
{
Chart2.Series["Default"].LegendText = column.ToString();
}
Thks - in your loop through the columns, you can get the column name from each. But since you are skipping the first column for the data, the first point is using the data from the second column. So you just have to offset the index by 1.
this also has some code to add a Title to your Chart, using the value in the first column, so the data in the "State" column shows up on the chart
Private Sub btnGraph_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGraph.Click Chart1.Series(0).Points.Clear() Chart1.Titles.Clear() Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Pie Chart1.Series(0).IsValueShownAsLabel = True Chart1.Titles.Add(dtTest.Rows(DataGridView1.SelectedRows(0).Index).Item(0).ToString) For i As Integer = 1 To dtTest.Columns.Count - 1 Chart1.Series(0).Points.AddY(dtTest.Rows(DataGridView1.SelectedRows(0).Index).Item(i)) Chart1.Series(0).Points(i - 1).LegendText = dtTest.Columns(i).ColumnName.ToString Next End Sub
- The legends take binding from supplied table's column name also, if you don't know.
Try something like below :
SomeChart.Series[0].Legend = PieTable.Columns[0].ColumnName;
If you find solution from my answer, please mark it as answer.- Marked As Answer byAlex GorevMSFT, OwnerThursday, November 19, 2009 5:36 AM


