Kendo UI图表颜色

Car*_*pon 4 javascript jquery telerik kendo-ui

我在配置Kendo UI柱形图的条形颜色时遇到问题.这是代码:

<!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>
Run Code Online (Sandbox Code Playgroud)

我试图将"C1"变为红色,将"C2"变为蓝色,但图表呈现如下屏幕截图:

在此输入图像描述

任何指向正确的方向将不胜感激.

Car*_*pon 16

在进一步研究之后,我发现colorField用于将颜色设置为系列中的单个点(而不是整个系列).我发现seriesColors是我想要的:

http://docs.kendoui.c​​om/api/dataviz/chart#configuration-seriesColors

这是我重构的例子:

<!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>
Run Code Online (Sandbox Code Playgroud)