How can I populate my Pie Area ChartView correctly...

4 posts, 2 answers
  1. Bullet
    Bullet avatar
    2 posts
    Member since:
    May 2014

    Posted 28 May 2014 Link to this post

    Hey I have recently installed Telerik UI for WinForm, I have used the Chart control of Visual Studio just fine using this code on FormLoad, It is working fine and I am attaching screenshots:

                DataSet dataSet;
                ConnectionClass.GetInstance().connection_string = Properties.Settings.Default.MindMuscleConnectionString;
                ConnectionClass.GetInstance().Sql = "Select Count(MemberInfo.memberName) as 'Members', CompetitionName as 'Competition' FROM MemberInfo, MemberBodyInfo, Competition WHERE MemberInfo.memberID = MemberBodyInfo.memberID AND MemberBodyInfo.weight >= Competition.CompetitionCategory and MemberBodyInfo.weight <= Competition.CompetitionCategory + 5 group by CompetitionName;";
                dataSet = ConnectionClass.GetInstance().GetConnection;
                chart1.Series["Series1"].Name = "Members";
                chart1.Series["Members"].YValueMembers = "Members";
                chart1.Series["Members"].XValueMember = "Competition";

                this.chart1.Titles.Add("Competition Participants");   // Set the chart title
                chart1.Series["Members"].ChartType = SeriesChartType.Pie;
                chart1.Series["Members"].IsValueShownAsLabel = true;  // To show chart value 
                chart1.DataSource = dataSet;
                chart1.DataBind();
    I can not do the same thing on Telerik ChartView. How can I do this ? So far I have tried setting the datasource and datamember and got this so far... 

    Please help





  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 29 May 2014 Link to this post

    Hi Syed,

    Thank you for writing.

    Please refer to the following code snippet demonstrating how to achieve the same appearance like with the standard control:
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
     
        InitializeComponent();
     
        radChartView1 = new RadChartView();
        radChartView1.Parent = this;
     
        DataTable t = new DataTable();
        t.Columns.Add("Members");
        t.Columns.Add("Competition");
     
        t.Rows.Add(":P", 3);
        t.Rows.Add("Arnold Classic Karachi", 3);
        t.Rows.Add("Iron Patriot", 1);
        t.Rows.Add("Karachi Pro", 3);
        t.Rows.Add("Smart", 2);
        t.Rows.Add("Titans Pro Karachi", 1);
     
        radChartView1.AreaType = ChartAreaType.Pie;
     
        PieSeries series = new PieSeries();
        series.DisplayMember = "Members";
        series.ValueMember = "Competition";
        series.ShowLabels = true;
        series.LabelsOffsetFromCenter = 0.6f;
     
        radChartView1.DataSource = t;
        radChartView1.Series.Add(series);
     
        radChartView1.Title = "Competition Participants";
        radChartView1.ShowTitle = true;
        radChartView1.ShowLegend = true;
     
        radChartView1.LabelFormatting += radChartView1_LabelFormatting;
     
    }
     
    void radChartView1_LabelFormatting(object sender, ChartViewLabelFormattingEventArgs e)
    {
        PieDataPoint dataPoint = (PieDataPoint)e.LabelElement.DataPoint;
        e.LabelElement.Text = dataPoint.Value.ToString();
    }

    Let me also provide a couple articles you might find useful:

    I hope this helps.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bullet
    Bullet avatar
    2 posts
    Member since:
    May 2014

    Posted 31 May 2014 in reply to Stefan Link to this post

    Thank you for your reply. I was able to achieve what I wanted from your post. However what you did was hard coded the data but I do not want that. So I changed it a little bit :

    private void EquipmentChart_Load(object sender, EventArgs e)
            {
                DataSet dataSet;
                ConnectionClass.GetInstance().connection_string = Properties.Settings.Default.MindMuscleConnectionString;
                ConnectionClass.GetInstance().Sql = "select Equipment.EquipmentName as Name, Equipment.EquipmentQuantity as Quantity from Equipment;";
                dataSet = ConnectionClass.GetInstance().GetConnection;
                radChartView1.AreaType = ChartAreaType.Pie;
     
                PieSeries series = new PieSeries();
                series.DisplayMember = "Name";
                series.ValueMember = "Quantity";
                series.ShowLabels = true;
                //series.LabelsOffsetFromCenter = 0.6f;
                radChartView1.ShowToolTip = true;
                series.DrawLinesToLabels = true;
     
     
                radChartView1.DataSource = dataSet.Tables[0];
                radChartView1.Series.Add(series);
     
                radChartView1.Title = "Equipment Quantity";
                radChartView1.ShowTitle = true;
                radChartView1.ShowLegend = true;
     
                radChartView1.LabelFormatting += radChartView1_LabelFormatting;
     
            }
     
            void radChartView1_LabelFormatting(object sender, ChartViewLabelFormattingEventArgs e)
            {
                PieDataPoint dataPoint = (PieDataPoint)e.LabelElement.DataPoint;
                e.LabelElement.Text = dataPoint.Value.ToString();
            }
    and I achieved this: 
    Picture1, 
    If it is not so much trouble please can you tell me how can I achieve this:
    Picture2?
    I dont want the data I just want the view, like how to make that hole in the pie? and how to make the tooltips enabled?
    Also If you can suggest anything else to make the chart look more awesome and cool. That would be great.

  5. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 02 Jun 2014 Link to this post

    Hi,

    To achieve the desired look you should use Donut series. Please refer to the following article for more information: http://www.telerik.com/help/winforms/chartview-series-types-donut.html

    To enable the labels, you need to set the ShowLabels property of the series tot true.

    I hope this helps.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top