2

Is it possible to remove the kendo pie chart label which are displaying "0%". But we can display the legends though there are no data for that.

Below is a link which displays "0%" for Rain.

http://dojo.telerik.com/ewALo

Please suggest me with your valuable ideas. Thanks.

Karthik
  • 65
  • 1
  • 10

2 Answers2

5

You can use the labels.visual property. With a template of "#: value #%", only return a label in the visual property if the text is not "0%":

  labels: {
    visible: true,                   
    position: "insideEnd", 
    template: "#: value #%",
    visual: function(e) {
      if (e.text != "0%") {   
        return e.createVisual(); 
      }
    }
  }

Updated DEMO

UPDATE: This can also be easily accomplished with just a label template:

labels: {
  visible: true,                   
  position: "insideEnd", 
  template: "#if (value > 0) {# #: value #% #}#",  
}

DEMO

ezanker
  • 24,628
  • 1
  • 20
  • 35
  • Thanks ezanker. I am sorry, I didn't mention the Kendo UI package I am using to do this. It is "2015.1.318". I think the labels.visual property is supported in the latest version. I am still trying for a work around. – Karthik Dec 13 '17 at 06:07
  • 1
    @Karthik, i realized you can do this with just a template: template: "#if (value > 0) {# #: value #% #}#" DEMO: http://dojo.telerik.com/@ezanker/ipeyoT – ezanker Dec 13 '17 at 14:44
  • Awesome buddy. You rocked. Your efforts are much appreciated. Enjoy your year end and have a Successful 2018. Merry Christmas in Advance.. – Karthik Dec 15 '17 at 11:49
1

You could remove the items with a zero value from the dataSource view data.

, dataBound: (function(e) {
    var oa = e.sender.dataSource.view();
    for (var i = oa.length-1; i >= 0; i--) {
      if (oa[i].percentage == 0) { oa.splice(i,1); }
    }
  })

Of course this adjustment removes the rain item from the legend as well. I think that would be ok -- having an item in the legend that has no corresponding slice or category label could be confusing.

Richard
  • 25,390
  • 3
  • 25
  • 38
  • Thanks Richard. I agree with you. If the Rain items doesn't have any value it is not necessary that we should display that. But the business requirement is the other way and they need the legend. This will help me someday. Much appreciated. – Karthik Dec 13 '17 at 06:09