We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Chart point as string

Thread ID:

Created:

Updated:

Platform:

Replies:

123394 Mar 14,2016 09:24 AM Mar 15,2016 08:38 AM Windows Forms 1
loading
Tags: Chart
Jason
Asked On March 14, 2016 09:24 AM

I'm extracting data from my database which consists of text and a number (count).  but the chart data points appear not to accept string input.  
An example of my data;

Hats 167
Scarf 1103
Tie 372
Shoes   6

Form this I'm trying to create a Pie chart.   How can this be done?

Sanjith Kesavan [Syncfusion]
Replied On March 15, 2016 08:38 AM

Hi Jason,

Thanks for contacting Syncfusion support. We have analyzed your query and prepared sample based on your requirement. Currently we are not having support category axis (binding string values for axis). So for the pie chart we have bound only the Y-values and chart will consider the index as X-value. In the sample, we have retrieved data from the database and bound this data to the chart. Please follow the below code example.
[CS]

var data = PullData();

ChartDataBindModel Series1Model = new ChartDataBindModel();

Series1Model.DataSource = data;

Series1Model.YNames = new string[] { "YValue" };

ChartSeries series1 = new ChartSeries();
series1.Type = ChartSeriesType.Pie;


In the above code we bound “data” as datasource for the series. Data contains string and integer value. For the YNames we have bound “YValue” in the data. Now the chart will be render like below.

If the DisplayText is set as true, then y-values are displayed in the labels for pie chart. Please refer the below screenshot.

If you want to modify this labels with the x-values bound for the datasource please follow the below code.

series1.Style.DisplayText = true;

or (int k = 0; k < data.Count; k++)

{

    series1.Styles[k].Text = data[k].XValue;
}


In the above code, we have set displaytext as true and changed the label text for the each points with the string values from the database. Now the chart labels will modified like below.

We have prepared sample as per your requirement. Please find the sample from below location
Sample link: http://www.syncfusion.com/downloads/support/forum/123394/ze/Pie-1320397341
Regards,
Sanjith.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;