This is a migrated thread and some comments may be shown as answers.
Help !!!!
1 Answer 27 Views
This is a migrated thread and some comments may be shown as answers.
Ketan
Top achievements
Rank 1
Ketan asked on 04 Jan 2012, 09:06 AM
Hello team,

We are using telerik charting .We have used below code for generating chart.When we are using below code we get error in stack area and stack line chart.

please find attached screen shot for error.
how can i use below code for pie chart because i am not able to generate pie chart using below code.we have two columns for pie chart x-axis and category.
 
Code:
           SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ChartconnectionString"].ConnectionString);
            cn.Open();
            SqlCommand cmd = new SqlCommand(query, cn);
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            DataTable data = new DataTable();
            sda.Fill(data);
          RadChart1.DataSource = data;
 

         RadChart1.DataManager.ValuesYColumns = new string[] { rcbyaxis.SelectedItem.Text };//Y-axis column
        RadChart1.PlotArea.XAxis.DataLabelsColumn = rcbxaxis.SelectedItem.Text;//X-axis column

         RadChart1.DataGroupColumn = rcbCategory.SelectedItem.Text;//Category column for stack chart
            RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 300;
            RadChart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color =
            System.Drawing.Color.BlueViolet;
            RadChart1.PlotArea.Appearance.Dimensions.Margins.Bottom =
            Telerik.Charting.Styles.Unit.Percentage(30);
            switch (rcbChartType.SelectedValue)
            {
                case "BAR":
                    RadChart1.Chart.DefaultType = ChartSeriesType.Bar;
                    break;
                case "Line":
                    RadChart1.Chart.DefaultType = ChartSeriesType.Line;
                    break;
                case "Area":
                    RadChart1.Chart.DefaultType = ChartSeriesType.Area;
                    break;
                case "Stacked Bar":
                    RadChart1.Chart.DefaultType = ChartSeriesType.StackedBar;
                    break;
                case "Stacked Line":
                    RadChart1.Chart.DefaultType = ChartSeriesType.StackedLine;
                    break;
                case "Stacked Area":
                    RadChart1.Chart.DefaultType = ChartSeriesType.StackedArea;
                    break;
                case "Stacked Bar 100%":
                    RadChart1.Chart.DefaultType = ChartSeriesType.StackedBar100;
                    break;
                case "Stacked Area 100%":
                    RadChart1.Chart.DefaultType = ChartSeriesType.StackedArea100;
                    break;
                case "Pie":
                    RadChart1.Chart.DefaultType = ChartSeriesType.Pie;
                    break;
            }
            // bind to the datasource
            RadChart1.DataBind();
 

please help me as soon as possible.
Thanks.

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 05 Jan 2012, 05:07 PM
Ketan:

The "error.png" shows an exception based on the selection of a Stacked Line chart, correct? There is a RadChart hide empty values forum thread that provides (at the bottom) some insights on a workaround which might help you here.

But, what is the error or the problem that occurs when you select the Pie Chart rendering option? Please provide more insight so that I can attempt to assist you.

See the Creating RadChart Programmatically and the Creating RadChart Programmatically - more complex example documentation page for insights.

Although they don't go over exactly how to create a pie chart you simply have to set the type of the series like this example:

protected void testButton_Click(object sender, EventArgs e)
{
    ChartSeries mySeries = new ChartSeries();
    ChartSeriesItem myItem = new ChartSeriesItem();
 
    myItem.YValue = 10;
    mySeries.AddItem(myItem); 
    mySeries.Type = ChartSeriesType.Pie;
    RadChart1.Series.Add(mySeries);
    RadChart1.DataBind();
}


Hope this helps!

Regards,
Asked by
Ketan
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or