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

Label Templates based on series fields from JSON

1 Answer 106 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Devendra
Top achievements
Rank 1
Devendra asked on 29 Jul 2015, 07:13 AM

 Hello,

I have below stacked type chart where it display data from a service. I want to display the label value dynamically for each field in the series. Here i have Value and UnusedValue, how to display these values for their respective fileds "Used Capacity" and "Unused Capacity". The below code displays the same value for both fields because the label template doesn't have any condition.

function createchart(chartID, chartTitle) {
     $(chartID).kendoChart({
         dataSource: {
             transport: {
                 read: {
                     url: serviceurl,
                     dataType: "json"
                 }
             }
         },
         title: {
             text: "RAU"
         },
 
         legend: {
             position: "right"
         },
         seriesDefaults: {
             type: "column",
             stack: {
                 type: "100%"
             },
             labels: {
                 visible: true,
                 position: "bottom",
                 template: "#= dataItem.Value #%"
             }
         },
         series: [{
             name: "Used Capacity",
             field: "Value",
             CategoryField: "RAU"
         }, {
             name: "Unused Capacity",
             field: "UnusedValue",
             CategoryField: "RAU",
             color: "#FFFFFF"
         }],
         valueAxis: {
             line: {
                 visible: false
             },
             minorGridLines: {
                 visible: true
             },
             visible: false
         },
         categoryAxis: {
             categories: ["Reliability", "Availability", "Utilisation"],
             majorGridLines: {
                 visible: false
             }
         },
         tooltip: {
             visible: true,
             template: "#= series.name #: #= dataItem.Value #"
         }
     });
 }

Best Regards,

Devendra

1 Answer, 1 is accepted

Sort by
0
Accepted
Plamen Lazarov
Telerik team
answered on 31 Jul 2015, 07:00 AM

Hello Devendra,

In order to achieve the expected you should use custom JavaScript logic in the seriesDefaults.labels.template function. Please find below a basic example which demonstrates this approach:
http://dojo.telerik.com/AzAji

Regards,
Plamen Lazarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Charts
Asked by
Devendra
Top achievements
Rank 1
Answers by
Plamen Lazarov
Telerik team
Share this question
or