0

when i bind data with multiple series in stacked coulmn chart, only first series is
showed with data other series are not showed.i iterate through series and add points toseries dynamiccally but problem is still existing. i also set isshowedaslabel
property to true but problem is not soving please help me .

aspx Code:

                 XValueMember="qno"   YValueMembers="option3" ></asp:Series>
                        <asp:Series Name="Series2" ChartType="StackedColumn"   

                   XValueMember="description" YValueMembers="option3"></asp:Series>
                            <asp:Series Name="Series3" ChartType="StackedColumn" 

                      XValueMember="option1" YValueMembers="option3"></asp:Series>
                                <asp:Series Name="Series4" ChartType="StackedColumn"  

                   XValueMember="description" YValueMembers="option3">   
                    </asp:Series>
                </Series

>





            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>


    **.aspx.cs**
     assessdal d = new assessdal();
            SqlConnection con = dbconnect.GetConnection();

            SqlCommand cmd = new SqlCommand("select assessid, qno ,description,    
           option1,option2,option3,option4 from assessmenttest", con);
            SqlDataReader reder = cmd.ExecuteReader();








                Chart2.DataSource = d.showop1();

                Chart2.DataBind();



                Chart2.Series["Series1"].IsValueShownAsLabel = true;


                Chart2.Series["Series2"].IsValueShownAsLabel = true;
                Chart2.Series["Series3"].IsValueShownAsLabel = true;
                Chart2.Series["Series4"].IsValueShownAsLabel = true;
                while (reder.Read())
                {
                    if (reder.HasRows)
                    {

                        //Chart2.Series["Series1"].Points.DataBindY(reder, "option3");
                        //Chart2.Series["Series2"].Points.DataBindY(reder, "option3");
                        //Chart2.Series["Series3"].Points.DataBindY(reder, "option3");
                        //Chart2.Series["Series4"].Points.DataBindY(reder, "option3");
                    }
                    foreach (Series s in Chart2.Series)
                    {
                        s.Points.DataBindY(reder,"option3");
                    }




                }
user1405508
  • 35
  • 2
  • 14

2 Answers2

0

I recommend using the DataBindCrossTable method instead for binding data to a stacked bar/stacked column chart. Have a look at the example here:

http://blogs.msdn.com/b/saveenr/archive/2012/01/25/microsoft-chart-controls-using-databindcrosstable-method-for-dynamic-series.aspx

The method basically does a GROUP BY operation on the specified column and creates a chart series for each distinct value in that column.

kad81
  • 10,712
  • 3
  • 38
  • 44
0

The example @kad81 references has moved, and it did not address the chart type. In my experience DataBindCrossTable defaulted to a column chart.

Here is the relevant code snippet from the example, plus I added the loop at the bottom to handle the stacked column chart style.

// Setup the data
var dt = new System.Data.DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("BugCount", typeof(int));
dt.Columns.Add("Day", typeof(int));
dt.Rows.Add("Kim", 10, 0);
dt.Rows.Add("Kim", 12, 1);
dt.Rows.Add("Kim", 18, 2);
dt.Rows.Add("Kim", 5, 3);
dt.Rows.Add("Philby", 18, 0);
dt.Rows.Add("Philby", 25, 1);
dt.Rows.Add("Philby", 9, 2);
dt.Rows.Add("Philby", 32, 3);

// Build the chart
this.chart1.Series.Clear();
this.chart1.DataBindCrossTable(dt.Rows, "Name", "Day", "BugCount", "");

foreach (Series s in this.chart1.Series)
{
    s.ChartType=SeriesChartType.StackedColumn;
}
vpipkt
  • 1,710
  • 14
  • 17