This is a migrated thread and some comments may be shown as answers.

Problem for creating Pie chart

7 Answers 166 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
amrutha anil
Top achievements
Rank 1
amrutha anil asked on 01 Mar 2010, 02:25 AM
Hai,
I'm creating a simple program to display some values in a chart. The user can select the type of chart.But I'm having problem to create the pie chart. The problem is that I cannot combine two values into a single pie.Instead only by creating two chartseries. Pls help me to rectify the problem.
Thanks

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using Telerik.Charting; 
using Telerik.WinControls.UI; 
using Telerik.WinControls; 
using Telerik.WinControls.Primitives; 
using FrmErdStatusChart.CallSignWebService; 
using System.Collections; 
 
 
 
namespace FrmErdStatusChart 
    public partial class Form1 : RadForm 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
            radChart1.ChartTitle.TextBlock.Text = "Status Chart"
            radChart1.Appearance.Border.Visible = false
            radChart1.Appearance.FillStyle.MainColor = Color.Lavender; 
            radChart1.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.Black; 
            this.radChart1.Series[0].Appearance.LegendDisplayMode = Telerik.Charting.ChartSeriesLegendDisplayMode.Nothing; 
            this.radChart1.Series[1].Appearance.LegendDisplayMode = Telerik.Charting.ChartSeriesLegendDisplayMode.Nothing; 
             
        } 
        CallSignWebService.CallSignWebService callsignWS = new CallSignWebService.CallSignWebService(); 
        ArrayList statusArray = new ArrayList(); 
        ChartSeries cs = new ChartSeries(); 
        ChartSeries cs1 = new ChartSeries(); 
         
 
        int online ; 
        int offline ; 
        string[] status = {"online" , "offline" }; 
 
 
        //Add the status ==> online 
        public void AddAvailable() 
        { 
            cs.Clear(); 
            cs.Items.Add(new ChartSeriesItem(online)); 
            radChart1.Series.Add(cs); 
            cs.Name = "Online " + online; 
            radChart1.DataBind(); 
        } 
 
        //Add status ==> offline 
        public void AddOffline() 
        { 
            cs1.Clear(); 
            cs1.Items.Add(new ChartSeriesItem(offline)); 
            radChart1.Series.Add(cs1); 
            cs1.Name = "offline "+offline; 
            radChart1.DataBind(); 
        } 
 
 
        //Get the status from the callsign 
        public void addStatus() 
        { 
            callSign[] callSignList = callsignWS.findAll(); 
            foreach (callSign callSign in callSignList) 
            { 
               statusArray.Add(callSign.status); 
           ///// Console.WriteLine(callSign.unit); 
                 
            } 
           
        } 
 
        //filter out the status according to online,offline 
        public void addChart() 
        { 
            online = 0
            offline = 0
             
             
          /*  for (int i = 0; i < statusArray.Count; i++) 
            { 
                //counts status ==> online 
                foreach (string online in statusArray) 
                { 
                    o++; 
                } 
                //counts status ==> offline 
                foreach (string offline in statusArray) 
                { 
                    f++; 
                } 
                break; 
            }*/ 
            for (int i = 0; i < statusArray.Count;i++ ) 
            { 
                if (statusArray[i].ToString() == "Online") 
                { 
                    online++; 
                } 
                else offline++; 
 
            } 
            Console.WriteLine("Online ==> "+online); 
            Console.WriteLine("Offline ==> "+offline); 
          
        } 
         
 
        private void radComboBox1_SelectedValueChanged(object sender, EventArgs e) 
        { 
 
        } 
 
        private void radComboBox1_SelectedIndexChanged(object sender, EventArgs e) 
        { 
 
            // Check whether an item in combo box is selected 
            if (radComboBox1.SelectedItem != null) 
            { 
                //value is equal to pie 
                if (radComboBox1.SelectedIndex == 0) 
                { 
                  /*  radChart1.Series.Clear(); 
                    ChartSeries cs2 = new ChartSeries(); 
                    cs2.Type = ChartSeriesType.Pie; 
                     
                    radChart1.Series.Add(cs2); 
                    radChart1.DataSource = new int[] {o,f }; 
                    radChart1.DataBind();*/ 
 
                    AddOffline(); 
                    AddAvailable(); 
                     
                    cs.Type = ChartSeriesType.Pie; 
                    cs1.Type = ChartSeriesType.Pie; 
 
                } 
                //value is equal to bar 
                else if (radComboBox1.SelectedIndex == 1) 
                { 
 
                    AddOffline(); 
                    AddAvailable(); 
                    cs.Type = ChartSeriesType.Bar; 
                    cs1.Type = ChartSeriesType.Bar; 
  
                } 
                //Value is equal to point 
                else if (radComboBox1.SelectedIndex == 2) 
                { 
 
                    AddOffline(); 
                    AddAvailable(); 
                    cs.Type = ChartSeriesType.Point; 
                    cs1.Type = ChartSeriesType.Point; 
 
                } 
            } 
        } 
 
        private void Form1_Load(object sender, EventArgs e) 
        { 
            addStatus(); 
            addChart(); 
        } 
    } 
 

7 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 03 Mar 2010, 08:27 AM
Hello amrutha anil,

I am not sure what is that you want to achieve.  Please, provide sketch of what you expect to see and a screenshot of what the actual result is.

Best,
Joshua
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
amrutha anil
Top achievements
Rank 1
answered on 03 Mar 2010, 08:36 AM
Hai Joshua ,
Thanks for the response.I wanted to get a single pie chart for the two values 'online' and 'offline'. What i'm getting now is two different pie charts. I have attached the screenshot of the result.
Thanks.
0
Dwight
Telerik team
answered on 05 Mar 2010, 08:07 AM
Hello amrutha,

What I see here is that in each and every case you create two data series for online and for offline, each containing a single data point. The Pie chart, however, generates one pie per series.

In order for the Pie scenario to work, you will need add both values in one ChartSeries instead of two.

Best wishes,
Joshua
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
amrutha anil
Top achievements
Rank 1
answered on 05 Mar 2010, 08:24 AM
Hai Joshua,

I tried to create the pie chart with a single chartseries. But I failed. Can you please give me an example on how to do it.

Thanks a lot!
0
amrutha anil
Top achievements
Rank 1
answered on 10 Mar 2010, 01:58 AM
Hai Joshua,

Can you please help me by giving some code snippets to solve my problem. It will be a great help!
Thanks.
0
Accepted
Dwight
Telerik team
answered on 10 Mar 2010, 08:09 AM
Hello amrutha anil,

For the Pie, you need to use a single series:
public void AddForPieChart()
{
    radChart1.Series.Clear();
 
    ChartSeries cs = new ChartSeries();
    cs.Type = ChartSeriesType.Pie;
 
    ChartSeriesItem onlineItem = new ChartSeriesItem(online);
    onlineItem.Name = "Online " + online;
 
    ChartSeriesItem offlineItem = new ChartSeriesItem(offline);
    offlineItem.Name = "Offline " + offline;
 
    cs.Items.Add(onlineItem);
    cs.Items.Add(offlineItem);
 
    radChart1.Series.Add(cs);
}

For the Bar and Point you can use the same approach, but in order to get different colors and for the items, as well as different legend items, you need to set:
cs.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;

Best,
Joshua
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
amrutha anil
Top achievements
Rank 1
answered on 10 Mar 2010, 08:26 AM
Hai Joshua,

It worked for me...Thanks for your support and thanks to Telerik Team.
Tags
Chart (obsolete as of Q1 2013)
Asked by
amrutha anil
Top achievements
Rank 1
Answers by
Dwight
Telerik team
amrutha anil
Top achievements
Rank 1
Share this question
or