Kendo UI图表categoryaxis日期分组日期

时间:2015-04-15 05:55:33

标签: user-interface charts kendo-ui kendo-chart

我的json:

 var stats = [
     { value: 30, date: new Date("2015/04/12"), No: 1 },
     { value: 50, date: new Date("2015/04/12"), No: 2 },
     { value: 45, date: new Date("2015/04/12"), No: 3 },
     { value: 30, date: new Date("2015/04/13"), No: 1 },
     { value: 50, date: new Date("2015/04/13"), No: 2 },
     { value: 45, date: new Date("2015/04/13"), No: 3 },
     { value: 30, date: new Date("2015/04/14"), No: 1 },
     { value: 50, date: new Date("2015/04/14"), No: 2 },
     { value: 45, date: new Date("2015/04/14"), No: 3 }
];

我的代码:

function createChart() {
    $("#chart").kendoChart({
        title: {
            text: "72小时能耗状况图"
        },
        dataSource: {
            data: stats
        },
        seriesColors: ["#3A5FCD"],
        series: [{
            type: "column",
            field: "value",
            categoryField: "date"
        }],
        categoryAxis: {
            baseUnit: "days",
            majorGridLines: {
                visible: false
            }
        },
        valueAxis: {
            line: {
                visible: false
            }
        }
    });
}

我想每天有三个酒吧,1,2,3。 不同的日子有不同的颜色。

如何修改代码?

你能理解我吗?

1 个答案:

答案 0 :(得分:0)

设置一个dataSource对象,并在" No"上进行分组。字段:

var statsDataSource = new kendo.data.DataSource({
    data: stats,
    group: {
        field: "No"
    },
    sort: {
        field: "date",
        dir: "asc"
    },
    schema: {
        model: {
            fields: {
                date: {
                    type: "date"
                }
            }
        }
    }
});

然后在创建图表时使用该dataSource:

$("#chart").kendoChart({
    title: { text: "72小时能耗状况图" },
    theme: "Metro",
    dataSource: statsDataSource,                
    series: [{
        type: "column",
        field: "value",
        categoryField: "date",
        name: "#= group.value #"
    }],
    legend: {
        position: "bottom"
    },
    valueAxis: {
        line: {
           visible: false
        }
    },
    categoryAxis: {
      baseUnit: "days",
      majorGridLines: {
          visible: false
      }
    }
});
  

<强> DEMO