Trying to show a pie chart, but a bar chart displays ?

3 posts, 0 answers
  1. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2010 Link to this post

    Sorry for the noob question, but why don't I see a pie chart ?

    <UserControl x:Class="radPie.MainPage"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
        <Grid x:Name="LayoutRoot" Background="White">
            <telerik:RadChart Name="myPie"/>
            <Button Content="Next" Click="ShowChart" Width="50" Height="25" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        </Grid>
    </UserControl>


    using System;
    using System.Collections.Generic;
    using System.Windows.Controls;
      
    using Telerik.Windows.Controls.Charting;
      
    namespace radPie
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                myPie.DefaultView.ChartTitle.Content = "My Pie";
                myPie.DefaultSeriesDefinition = new PieSeriesDefinition();
                ShowChart(null,null);
            }
      
            public void ShowChart(object sender, System.Windows.RoutedEventArgs e)
            {
                Random random = new Random();
                List<string> fruits = new List<string>() { "Apples", "Oranges", "Pears", "Peaches", "Bananas", "Grapes" };
                myPie.DefaultView.ChartArea.DataSeries.Clear();
                foreach (string s in fruits)
                {
                    DataSeries series = new DataSeries() { LegendLabel = s };
                    series.Add(new DataPoint(random.Next(0, 50)));
                    myPie.DefaultView.ChartArea.DataSeries.Add(series);
                }
            }
        }
    }
  2. scott
    scott avatar
    67 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2010 Link to this post

    Nevermind - I see that I created 6 series ... I changed it to create one series with six data points ...

    public void ShowChart(object sender, System.Windows.RoutedEventArgs e)
       {
           Random random = new Random();
           List<string> fruits = new List<string>() { "Apples", "Oranges", "Pears", "Peaches", "Bananas", "Grapes" };
           myPie.DefaultView.ChartArea.DataSeries.Clear();
           DataSeries series = new DataSeries() { Definition = myPie.DefaultSeriesDefinition };
           foreach (string s in fruits)
           {
               DataPoint dp = new DataPoint(random.Next(0, 50)) { LegendLabel = s };
               series.Add(dp);
           }
           myPie.DefaultView.ChartArea.DataSeries.Add(series);
       }

    Seems to work.  I'd delete the thread if I could...Anyway, am I using this correctly ?

    Thanks ;)
  3. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 16 Jul 2010 Link to this post

    Hello scott,

    Besides manual creation of DataSeries, you might consider the built-in databinding support as well -- you can find a number of topics that discuss how to populate the control with data here.

    Hope this helps.


    Best wishes,
    Freddie
    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
Back to Top