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

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

2 Answers 39 Views
Chart
This is a migrated thread and some comments may be shown as answers.
scott
Top achievements
Rank 1
scott asked on 14 Jul 2010, 05:53 PM

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 Answers, 1 is accepted

Sort by
0
scott
Top achievements
Rank 1
answered on 14 Jul 2010, 06:32 PM

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 ;)
0
Giuseppe
Telerik team
answered on 16 Jul 2010, 04:35 PM
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
Tags
Chart
Asked by
scott
Top achievements
Rank 1
Answers by
scott
Top achievements
Rank 1
Giuseppe
Telerik team
Share this question
or