Customizing the colors of individual series in HighCharts

前端 未结 3 1093
旧时难觅i
旧时难觅i 2021-02-14 01:08

I am using HighCharts for a line graph and i am attemping to change the line color for each series. I did find this example here but the data is hard coded. My data is pulled fr

相关标签:
3条回答
  • 2021-02-14 01:46

    The color can be configured as part of the series. Try something like this:

    series: [
        {
            name: 'series I',
            color: '#ffffff',
            data: [17.4, 16.1, 19.45, 24.15, 28.44, 33.15, 37.2, 41.25, 43.3]
        }
    ];
    
    0 讨论(0)
  • 2021-02-14 02:01

    See the code (and the plot that it renders) below.

    The snippet below is a complete script--i.e., either put it in your markup between two script tags or as a stand-along js file with an includes in your markup.

    Colors is a Chart object so the easiest way is to pass an array of colors (as hex strings):

     $(function () {
        var chart;
        $(document).ready(function() {
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container',
                    type: 'line'
                },
                colors: ['#562F1E', '#AF7F24', '#263249', '#5F7F90', '#D9CDB6'],
                title: {
                   text: false
                },
                yAxis: {
                    title: {
                        text: false
                    }
               },
               series: [{
                    name: 'series I',
                    data: [17.4, 16.1, 19.45, 24.15, 28.44, 33.15, 37.2, 41.25, 43.3]
               },
               {
                    name: 'series II',
                    data: [13.19, 17.23, 25.74, 28.5, 33.9, 35.62, 37.0, 36.6, 34.82]
               }
               ]
            });
        });
    })
    

    enter image description here

    0 讨论(0)
  • 2021-02-14 02:06

    Top level config can contain colors field. It's an array from which series colors will be picked.

    See here.

    Here's working piece from my project

    var chart;
    $(document).ready(function () {
        chart = new Highcharts.Chart({
            chart:{
                renderTo:'perfchart',
                type:'line',
                marginRight:130,
                marginBottom:25
            },
            colors: ['#0000FF', '#0066FF', '#00CCFF'],
            title:{
                text:'Historical system performance',
                x:-20 //center
            },
    

    Appearance:

    highcharts colors

    0 讨论(0)
提交回复
热议问题