Reputation: 175
I want to customize label position of Telerik Donut Chart and it should look like expected image. I tried couple of settings but not able to adjust label position see poc image.
Questions - How to I change Label position so it looks like Expected image. I want 5,10,15,20,25, ... outside of 2nd ring and label should be end of each category.
Expected
POC
Code
$("#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"
}
}]
});
Upvotes: 4
Views: 487
Reputation: 1436
I don't know of any option that sets the particular placement you want, but you can trick Telerik to do it anyway. The key is to place the labels in a third, outer donut without background color and arrange the values of the slices such that they match the second (alternating gray) donut that now no longer needs labels.
$("#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"
}
}]
});
Now, you can of course replace the "X" with "" to get an empty top label, you can adjust the values of the third donut such that they fit more neatly, you can move the origin from 90 degrees to e.g. 89.5 degrees, you can us the same 9+1 scheme I used in the third donut also in the second donut to get your gray-with-tiny-white-separators layout etc etc.
Either way, that's the way I'd go: Make your second donut look any way you want, and use a basically invisible third donut to place your axis labels.
Neat, isn't it?
Upvotes: 4