Question

is it possible to make the color of axis to the same as the line of series? With this highcharts auto colourpicker. The colour should not be fixed.

I have multiple axis.

I mean when I insert line Highcharts library sets some color to the line, and after that i want set up the same color to axis that was setted up by Highcharts library automatically.

I tried to set the color like this, but it makes coloured only first axis, and to the wrong color.

                self.chart.addAxis(axisObject);
                self.chart.addSeries(seriesObject, false);

                for (var seriesName in series) {
                    var seriesObject = series[seriesName];
                    var id = seriesObject.userOptions.id;
                    if (id === sensorModel.get('id')) {
                        index = seriesObject._i;
                        color = seriesObject.color;
                        circle.css('background-color', color);

                        $(jqElement).removeClass('activeSensor');
                        $(jqElement).addClass('chartAdded');
                        var axisId = seriesObject.yAxis.userOptions.id;
                        for (var j = 0; j < self.chart.yAxis.length; j++) {
                            var yaxis = self.chart.yAxis[j];
                            if (yaxis.userOptions.id === axisId) {
                                yaxis.options.lineColor = color;
                                break;
                                //break;
                            }
                        } 
                        break;
                    }
                }

Thanks in advance

Was it helpful?

Solution

This can be done in the chart.events.load method using the axis.update() call:

chart: {
    events: {
        load: function (event) {
            this.yAxis[0].update({
                lineColor: this.series[0].color
            });
        }
    }
}

Live demo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top