Kendo UI-如何在条形图中更改X轴的颜色

时间:2014-05-20 12:48:01

标签: kendo-ui kendo-dataviz kendo-chart

以下是条形图的链接:http://jsfiddle.net/ZPUr4/143/

  1. 如何将X轴的颜色更改为0?
  2. 如何在栏顶部显示系列数据值?截至目前,它也会在底部显示负值。
  3. HTML code:

        <div id="example" class="k-content">
        <div id="chart"></div>
    </div>
    

    javascript代码:

    function createChart() {
            $("#chart").kendoChart({
                title: {
                    text: "Site Visitors"
                },
                legend: {
                    position: "bottom"
                },
                seriesDefaults: {
                    type: "column",
                    labels: {
                        visible: true,
                        background: "transparent",
    
                    }
                },
                series: [{
                    name: "Total Visits",
                    data: series1,
                    gap: 1.0,
                    spacing: 0
                }, {
                    name: "Unique visitors",
                    data: series2,
                    gap: 1.0
                }],
                valueAxis: {
                    min: -200000,
                    max: 200000,
                    axisCrossingValue: 50000,  
                    line: {
                        visible: false
                    },
                    title: {
                        text: "Availability"
                    },
    
                    color: 'blue'
                },
                categoryAxis: {
                   // categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
                    majorGridLines: {
                        visible: true,
                        position: "bottom"
                    }
                },
                tooltip: {
                    visible: true,
                    format: "{0}"
                }
            });
        }
    
    var series1=[56000, 63000, 74000, 91000, 117000, 158000];
    var series2= [-52000, 34000, 23000, -98000, 67000, 83000];
    
        $(document).ready(function () {
            createChart();
    
            $("#example").bind("kendo:skinChange", createChart);
    
            var chart = $("#chart").data("kendoChart"),
                firstSeries = chart.options.series;
        });
    

    感谢。

1 个答案:

答案 0 :(得分:3)

color上设置categoryAxis属性。

示例:

categoryAxis: {
    color: "blue",
    majorGridLines: {
        visible: true,
        position: "bottom"
    }
},

您的JSFiddle已修改:http://jsfiddle.net/OnaBai/ZPUr4/144/

关于如何在顶部定位值,您可以使用以下命令控制为所有系列定义默认属性的位置:

    seriesDefaults: {
        type: "column",
        labels: {
            visible: true,
            background: "transparent",
            position: "above",
            padding: -20
        }
    },

或为特定系列定义:

    series: [
        {
            name: "Total Visits",
            data: series1,
            gap: 1.0,
            spacing: 0
        }, 
        {
            labels: {
                position: "above",
                padding: -20
            },
            name: "Unique visitors",
            data: series2,
            gap: 1.0
        }
    ],

修改过的JSFiddle:http://jsfiddle.net/OnaBai/ZPUr4/150/