Problem for creating Pie chart

8 posts, 1 answers
  1. amrutha anil
    amrutha anil avatar
    8 posts
    Member since:
    Jan 2010

    Posted 28 Feb 2010 Link to this post

    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(); 
            } 
        } 
     

  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 03 Mar 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. amrutha anil
    amrutha anil avatar
    8 posts
    Member since:
    Jan 2010

    Posted 03 Mar 2010 Link to this post

    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.
  5. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 05 Mar 2010 Link to this post

    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.
  6. amrutha anil
    amrutha anil avatar
    8 posts
    Member since:
    Jan 2010

    Posted 05 Mar 2010 Link to this post

    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!
  7. amrutha anil
    amrutha anil avatar
    8 posts
    Member since:
    Jan 2010

    Posted 09 Mar 2010 Link to this post

    Hai Joshua,

    Can you please help me by giving some code snippets to solve my problem. It will be a great help!
    Thanks.
  8. Answer
    Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 10 Mar 2010 Link to this post

    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.
  9. amrutha anil
    amrutha anil avatar
    8 posts
    Member since:
    Jan 2010

    Posted 10 Mar 2010 Link to this post

    Hai Joshua,

    It worked for me...Thanks for your support and thanks to Telerik Team.
Back to Top
UI for WinForms is Visual Studio 2017 Ready