admin管理员组文章数量:1208155
I'm having trouble configuring the bar colors for a Kendo UI column chart. Here's the code:
<!DOCTYPE html>
<html xmlns="">
<head>
<title></title>
</head>
<body>
<div id="chart"></div>
<script src="js/thirdParty/jquery.js"></script>
<script src="js/thirdParty/kendo.all.min.js"></script>
<script>
$(function () {
var data,
dataSource;
data = [{
type: "C1",
amount: 100,
year: 2008,
color: "red"
}, {
type: "C2",
amount: 120,
year: 2008,
color: "blue"
}, {
type: "C2",
amount: 50,
year: 2009,
color: "blue"
}, {
type: "C1",
amount: 10,
year: 2010,
color: "red"
}, {
type: "C1",
amount: 120,
year: 2011,
color: "red"
}, {
type: "C2",
amount: 50,
year: 2011,
color: "blue"
}];
dataSource = new kendo.data.DataSource({
data: data,
group: {
field: "type"
},
sort: { field: "year" }
});
$("#chart").kendoChart({
dataSource: dataSource,
series: [{
type: "column",
field: "amount",
categoryField: "year",
name: "#= group.value #",
colorField: "color"
}],
})
});
</script>
</body>
</html>
I'm trying to get "C1" to be red and "C2" to be blue but the chart renders like in the following screen shot:
Any pointers in the right direction would be appreciated.
I'm having trouble configuring the bar colors for a Kendo UI column chart. Here's the code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="chart"></div>
<script src="js/thirdParty/jquery.js"></script>
<script src="js/thirdParty/kendo.all.min.js"></script>
<script>
$(function () {
var data,
dataSource;
data = [{
type: "C1",
amount: 100,
year: 2008,
color: "red"
}, {
type: "C2",
amount: 120,
year: 2008,
color: "blue"
}, {
type: "C2",
amount: 50,
year: 2009,
color: "blue"
}, {
type: "C1",
amount: 10,
year: 2010,
color: "red"
}, {
type: "C1",
amount: 120,
year: 2011,
color: "red"
}, {
type: "C2",
amount: 50,
year: 2011,
color: "blue"
}];
dataSource = new kendo.data.DataSource({
data: data,
group: {
field: "type"
},
sort: { field: "year" }
});
$("#chart").kendoChart({
dataSource: dataSource,
series: [{
type: "column",
field: "amount",
categoryField: "year",
name: "#= group.value #",
colorField: "color"
}],
})
});
</script>
</body>
</html>
I'm trying to get "C1" to be red and "C2" to be blue but the chart renders like in the following screen shot:
Any pointers in the right direction would be appreciated.
Share Improve this question asked Aug 27, 2013 at 4:33 Carl RipponCarl Rippon 4,6739 gold badges52 silver badges66 bronze badges2 Answers
Reset to default 17After looking into this further, I found that colorField is for setting color to a single point in the series (not to the entire series). I found seriesColors was what I was looking for:
http://docs.kendoui.com/api/dataviz/chart#configuration-seriesColors
Here is my refactored example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="chart"></div>
<script src="js/thirdParty/jquery.js"></script>
<script src="js/thirdParty/kendo.all.min.js"></script>
<script>
$(function () {
var data,
dataSource;
data = [{
type: "C1",
amount: 100,
year: 2008
}, {
type: "C2",
amount: 120,
year: 2008
}, {
type: "C2",
amount: 50,
year: 2009
}, {
type: "C1",
amount: 10,
year: 2010
}, {
type: "C1",
amount: 120,
year: 2011
}, {
type: "C2",
amount: 50,
year: 2011
}];
dataSource = new kendo.data.DataSource({
data: data,
group: {
field: "type"
},
sort: { field: "year" }
});
$("#chart").kendoChart({
dataSource: dataSource,
seriesColors: ["red", "blue"],
series: [{
type: "column",
field: "amount",
categoryField: "year",
name: "#= group.value #"
}],
})
});
</script>
</body>
</html>
check the JS Fiddle
http://jsfiddle.net/9VZdS/45/
$(function() {
var dataset = new Array(1,2,3,null,5,6);
var highlighted = new Array(null,null,null,4,null,null);
$('#chart').kendoChart({
theme: 'metro',
seriesDefaults: {
type: 'column',
stack: true
},
series: [
{
name: 'Not Highlighted',
data: dataset,
color: 'red'
},
{
name: 'Highlighted',
data: highlighted,
color: 'blue'
}
]
})
});
本文标签: javascriptKendo UI Chart ColorsStack Overflow
版权声明:本文标题:javascript - Kendo UI Chart Colors - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738689623a2107026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论