we recently bought telerik controls, and wanted to use html pie chart. Everything look working properly. However to display legent properly I have to create Series manually from code. But then if series is created manually, how can I set label? I can set label when data is databound - then legent is not wokring, or have legent but then I cannot set label.
12 Answers, 1 is accepted
Could you explain the problem in more detail, because I am not sure I can undestand you correctly?
You can add a PieSeries in the markup and set its properties related to labels and tooltips appearance (e.g. the DataFormatString) and then create the items in the code-behind - loop through the datasource, create SeriesItem instances and set their Name property according to your data, then add each item to the series.
You can find a simple example that shows this approach in action.
Kind regards,
Marin Bratanov
the Telerik team
First of all thank you for answer, but this is what I already new:
1. To have proper Legend for PieChar I have to create seriesitems in code behind.
2. To have proper Label description I have to bind PieChar and use DataField on label description.
I don't know how to have both.
I have label column in result with description (not number) it is combination of both. So when I'm binding chart label is displayed properly. But I don't have Legend, because Legened uses Names and cannot be binded.
When I'm not binding but creating SeriesItems in code I can have label only by formating e.g. Percentage, but not my descriptive label, because I cannot set label for SeriesItem.
I have added your idea to the PITS - a property that can be used for databinding the name of each series item in the same manner in which ColorField can be. You can monitor its progress and vote for it in this URL.
Regarding your exact scenario - I am afraid I still cannot understand the limitation. The DataFormatString for labels or tooltips of the series can use the YValue of the item at present and whether this property is set in the code-behind or in the markup there is no difference. The idea that more columns from a datasource can be added to a tooltip/label is logged in this PITS item, so you may find it interesting as well.
I believe my previous sample shows a relatively easy workaround for the time being that can enable you to use markup declaration for all common properties and only create items programmatically. Simply add the DataField="color" property to the LabelsAppearance tag of the PieSeries declaration and you will see the strings around the pie.
All the best,
Marin Bratanov
the Telerik team
How to explain it better.
1. DataFormatString is working for Label when I want to use YValue for labels. But I DON'T want. Each part of PIeChar has it own description e,g, car type: Toyota, Honda, Mercedes. And this is NOT possible with manual series creation. How ever I can do that with data binding.
2. Data binding however has different limitation. I cannot use Legend. Legend for PieChart can be only obtained by manual creation and using Name.
3. I just would like to have both Legend and Label, working on both modes: manual creation in code behind or data binding. Currently I can have only 1 working.
It seems you are using the DataField property of the LabelsAppearance tag. Indeed, currently both cannot be achieved and this is why I logged the PITS item that will provide sufficient functionality. Please accept my apologies for the inconvenience this may cause.
Greetings,
Marin Bratanov
the Telerik team
Hello Marcin
I was wondering if there is any update about this solution. I realized the PITS you provided do not work anymore. I am also trying to figure out if there is any straightforward way to add custom text/data in Labels in PieChart. I know that we are able to do it by binding the chart to a custom data source (i.e DataTable ) rather than adding PieSeries / SeriesItems into chart object; but I was wondering if there is any other way.
Thanks
Ahmet.
Hello Marin
I was wondering if there is any update about this solution. I realized the PITS you provided do not work anymore. I am also trying to figure out if there is any straightforward way to add custom text/data in Labels in PieChart. I know that we are able to do it by binding the chart to a custom data source (i.e DataTable ) rather than adding PieSeries / SeriesItems into chart object; but I was wondering if there is any other way.
Thanks
Ahmet.
Yes, the PieChart offers NameField property at this moment, you can see it in action in the following demo:
https://demos.telerik.com/aspnet-ajax/htmlchart/examples/clientsidedatabinding/defaultcs.aspx
Regards,
Vessy
Progress Telerik
Can that name field be accessed in jscript? I want to draw custom legend label using the nameField values, neither of the following work. The second option is close but not correct. I have my piechart bound to a sqlDataSource. In the attached photo, I want the legend to match the chart label, missing and leaked. Is this possible?
var label = new drawing.Text(e.series.name, [0, 0], {
fill: {
color: legendLabelsColor
}
})
or
var label = new drawing.Text(e.series.categoryName, [0, 0], {
fill: {
color: legendLabelsColor
}
})
I have just answered your other thread on the matter, you can refer my answer in it and continue our conversation there:
https://www.telerik.com/forums/pie-series-namefield-to-legend-label
Regards,
Vessy
Progress Telerik
Hello,
I added the chart in my code.after executing project no output is displyed
I will need to examined the exact setup you have in order to be able to say what is causing the faced issue. Please, follow the steps listed here and send me a runnable sample in which I can reproduce the issue and debug the reason of it:
https://www.telerik.com/blogs/isolating-a-problem-in-a-sample-project
Regards,
Vessy
Progress Telerik