Telerik Donut图表 - 自定义标签

时间:2015-01-08 22:07:05

标签: javascript html5 telerik donut-chart

我想自定义Telerik Donut Chart的标签位置,它应该看起来像预期的图像。我尝试了几个设置,但无法调整标签位置,请参阅poc图像。

问题 - 如何更改标签位置,使其看起来像预期图像。我想要5,10,15,20,25,......在第二个戒指之外,标签应该是每个类别的结尾。

预期

enter image description here

POC

enter image description here

代码

$("#chart").kendoChart({
  legend: {
    visible: false
  },
  chartArea: {
    background: ""
  },
  seriesDefaults: {
    type: "donut",
    startAngle: 90,
    labels:{
      template: "#= category #",
    }
  },
  series: [{
    name: "abc",
    size:50,
    margin:2,
    data: [{
      category: "abc1",
      value: 50,
      color: "#7FBA00"
    },{
      category: "abc2",
      value: 20,
      color: "#007233"
    },{
      category: "abc3",
      value: 30,
      color: "#D2D2D2"
    }]
  }, {
    name: "xyz",
    size:10,
    data: [{
      category: "5",
      value: 10,
      color: "#ccc"
    },{
      category: "10",
      value: 10,
      color: "#AFAFAF"
    },{
      category: "15",
      value: 10,
      color: "#ccc"
    },{
      category: "20",
      value: 10,
      color: "#AFAFAF"
    },{
      category: "25",
      value: 10,
      color: "#ccc"
    },{
      category: "30",
      value: 10,
      color: "#AFAFAF"
    }],
    labels: {
      visible: true,
      background: "transparent",
      position: "center"
    }
  }]
});

1 个答案:

答案 0 :(得分:4)

我不知道有任何设置您想要的特定位置的选项,但您仍然可以欺骗Telerik进行操作。关键是将标签放在没有背景颜色的第三个外部甜甜圈中,并排列切片的值,使它们与现在不再需要标签的第二个(交替灰色)甜甜圈相匹配。 p>

enter image description here

$("#chart").kendoChart({
  legend: {
    visible: false
  },
  chartArea: {
    background: ""
  },
  seriesDefaults: {
    type: "donut",
    startAngle: 90,
    labels:{
      template: "#= category #",
    }
  },
  series: [{
    name: "yourData",
    size:50,
    margin:2,
    data: [{
      category: "abc1",
      value: 50,
      color: "#7FBA00"
    },{
      category: "abc2",
      value: 20,
      color: "#007233"
    },{
      category: "abc3",
      value: 30,
      color: "#D2D2D2"
    }]
  }, {
    name: "grayAxis",
    size:10,
    data: [{
      value: 10,
      color: "#ccc"
    },{
      value: 10,
      color: "#AFAFAF"
    },{
      value: 10,
      color: "#ccc"
    },{
      value: 10,
      color: "#AFAFAF"
    },{
      value: 10,
      color: "#ccc"
    },{
      value: 10,
      color: "#AFAFAF"
    }]
  } , {
    name: "numbers",
    size:10,
    data: [{
      category: "",
      value: 9,
      color: "none"
    },{
      category: "5",
      value: 1,
      color: "none"
    },{
      category: "",
      value: 9,
      color: "none"
    },{
      category: "10",
      value: 1,
      color: "none"
    },{
      category: "",
      value: 9,
      color: "none"
    },{
      category: "15",
      value: 1,
      color: "none"
    },{
      category: "",
      value: 9,
      color: "none"
    },{
      category: "20",
      value: 1,
      color: "none"
    },{
      category: "",
      value: 9,
      color: "none"
    },{
      category: "25",
      value: 1,
      color: "none"
    },{
      category: "",
      value: 9,
      color: "none"
    },{
      category: "X",
      value: 1,
      color: "none"
    }],
    labels: {
      visible: true,
      background: "transparent",
      template: "#= category #",
      position: "center"
    } 
  }]
});

现在,您当然可以将“X”替换为“”以获得空的顶部标签,您可以调整第三个圆环的值以使它们更整齐地适合,您可以将原点从90度移动到例如89.5度,你可以使用我在第三个甜甜圈中使用的同样的9 + 1方案,也可以在第二个甜甜圈中获得灰色的微小白色分隔符等等。

无论哪种方式,这就是我的方式:让你的第二个甜甜圈看起来任何你想要的方式,并使用一个基本上看不见的第三个甜甜圈来放置你的轴标签。

干净,不是吗?

相关问题