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. Image for the cookie policy date

Chart point as string

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?

1 Reply

SK Sanjith Kesavan Syncfusion Team March 15, 2016 12:38 PM UTC

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.

Loader.
Up arrow icon