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

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

3 Answers 81 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Bullet
Top achievements
Rank 1
Bullet asked on 28 May 2014, 06:05 PM
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





3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 29 May 2014, 10:35 AM
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.
 
0
Bullet
Top achievements
Rank 1
answered on 31 May 2014, 01:51 PM
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.

0
Accepted
Stefan
Telerik team
answered on 02 Jun 2014, 07:00 AM
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.
 
Tags
ChartView
Asked by
Bullet
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Bullet
Top achievements
Rank 1
Share this question
or