user2439903
user2439903

Reputation: 1307

Kendo UI- how to change color of the X axis in bar chart

Here is the link for the bar chart: http://jsfiddle.net/ZPUr4/143/

  1. How can i change the color of X-axis at 0?
  2. How to display the series data values at the top of the bar? As of now its getting displayed at the bottom for negative values as well.

HTML code:

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

javascript code:

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;
    });

Thanks.

Upvotes: 2

Views: 3775

Answers (1)

OnaBai
OnaBai

Reputation: 40887

Set color property on categoryAxis.

Example:

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

Your JSFiddle modified: http://jsfiddle.net/OnaBai/ZPUr4/144/

Regarding how to position values on top, you can control the position defining for all series the default property using:

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

or define it for a specific serie:

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

The modified JSFiddle: http://jsfiddle.net/OnaBai/ZPUr4/150/

Upvotes: 4

Related Questions