Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set highcharts line graph point colors to an array of colors?

Tags:

highcharts

I've spent some time poking around the API documentation, and I don't see a simple solution to my problem. This is what I'm looking for:

In a chart, I can set each line to be a different color I choose like

colors: [ 'red', 'green', 'blue ]

But what if I want the points to be different colors than the line?

I know I can set the

    plotOptions: {
        series: {
            marker: {
                fillColor: 'yellow',
                lineColor: 'yellow' 
            }
        }
    },

But what if I want each point marker to be a different color? (For instance, I want the blue line to have dark blue points, the red line the have dark red points, and the green line to have dark green points.

I think I want to do something along the lines of

borderColors: [ 'darkBlue', 'darkGreen', 'darkRed' ]

or whatever and the same with fillColors...

Is there any way I can do this easily that I've missed.

Thanks!

like image 854
creftos Avatar asked Nov 03 '22 05:11

creftos


1 Answers

Define the marker in the series...

I found this in the api:Highchart symbol api

Which links to this fiddle: High char jsfiddle

changed the code to work with colour:

$(function () {
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container'
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 316.4, 294.1, 195.6, 154.4],
        marker: {
                fillColor: '#f11',
                lineWidth: 2,
                lineColor: '999'
        }
    }, {
        data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5],
        marker: {
                fillColor: '#999',
                lineWidth: 2,
                lineColor: '#111' 
        }
    }]
});
});
like image 100
Mark Avatar answered Nov 08 '22 10:11

Mark