gpt4 book ai didi

javascript - Kendo UI 将 donut chart 的系列标签颜色更改为系列颜色

转载 作者:行者123 更新时间:2023-11-29 19:09:46 25 4
gpt4 key购买 nike

我正在使用 kendoUI 和 angular。我有一个 Kendo Donut 图表,如下所示。

<div class="center-pad" kendo-chart k-theme="['material']" k-chart-area="{height: 325, width: 480}" 
k-series="[{ type: 'donut',
field: 'percentage',
labels: {visible: true, template: '${value} ${category} ${dataItem.color}', position: 'outsideEnd', font: '15px Lato-Regular'},
categoryField: 'source',
explodeField: 'explode'}]"
k-series-click="actionChartClick" k-data-source="actionChartData">

我想将系列标签颜色作为系列颜色。在模板中,我可以通过 ${dataItem.color}

访问模板颜色

我试过设置,

k-series="[{ ...
labels: {visible: true, template: '${value} ${category}', position: 'outsideEnd', font: '15px Lato-Regular', color: '${dataItem.color}'}"

但这没有用。谁能指导我应该更改的地方?

最佳答案

使用 seriesDefaults.labels.colorseries.labels.color 并从函数返回所需的颜色值。您将有权访问函数参数中的 seriesdataItem

http://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/chart#configuration-series.labels.color

<!DOCTYPE html>
<html>
<head>
<base href="http://demos.telerik.com/kendo-ui/donut-charts/donut-labels">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.common.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.default.min.css" />

<script src="//kendo.cdn.telerik.com/2016.3.914/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.3.914/js/kendo.all.min.js"></script>
</head>
<body>
<div id="chart"></div>

<script>

$(function() {
$("#chart").kendoChart({
title: {
text: "What is you favourite sport?"
},
legend: {
position: "top"
},
seriesDefaults: {
labels: {
template: "#= category # - #= kendo.format('{0:P}', percentage)#",
position: "outsideEnd",
visible: true,
background: "transparent",
color: function(e) {
// e.series
// e.dataItem
if (e.category == "Football") {
return "#000";
} else {
return e.series.color;
}
}
}
},
series: [{
type: "donut",
labels: {
/*color: function(e) {
// e.series
// e.dataItem
if (e.category == "Football") {
return "#f00";
} else {
return e.series.color;
}
}*/
},
data: [{
category: "Football",
value: 35
}, {
category: "Basketball",
value: 25
}, {
category: "Volleyball",
value: 20
}, {
category: "Rugby",
value: 10
}, {
category: "Tennis",
value: 10
}]
}],
tooltip: {
visible: true,
template: "#= category # - #= kendo.format('{0:P}', percentage) #"
}
});

});

</script>

</body>
</html>

关于javascript - Kendo UI 将 donut chart 的系列标签颜色更改为系列颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39929562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com