我正在研究js.devexpress Pie Chart。我想在运行时更改系列颜色。
我从webservice获取数据,根据我的逻辑,我必须根据值更改颜色为红色或绿色。如果值小于0 [零]则饼图颜色为红色,否则为绿色。
我的代码是
<div id="canvas-holder" >
<div id="pie" ></div>
</div>
var pie = $("#pie").dxPieChart({
size: {width: 500},
//palette: "bright",
dataSource: [{country: "On",area: 0}],
series: [{argumentField: "country", valueField: "area"}],
title: "Area of Countries"
}).dxPieChart("instance");
setInterval(function () {
debugger;
pie.option("Color", "red");
pie.element().css({ Color: 'red' })
var chartOptions = pie.option();
pie.series[0].Color = "red";
pie.option(chartOptions);
}, 1000);
</script>
`
答案 0 :(得分:0)
我发现快速解决方案:访问More Details
的devexpress支持论坛代码是
<div id="canvas-holder">
<div id="pie"></div>
</div>
<script>
var ds = [{ country: "On", area: 0 }];
var pie = $("#pie").dxPieChart({
size: { width: 500 },
//palette: "bright",
dataSource: ds,
series: [{ argumentField: "country", valueField: "area" }],
title: "Area of Countries",
customizePoint: function (pointInfo) {
if (pointInfo.value <= 0) {
return {
color: "red"
}
}
return {
color: "green"
}
}
}).dxPieChart("instance");
var isVal = 0;
setInterval(function () {
if (isVal == 0)
isVal = 1;
else
isVal = 0;
ds[0].area = 1;
pie.option("dataSource", ds);
}, 1000);
</script>