PinoyCoder
PinoyCoder

Reputation: 1112

Preprocessing of dynamically added series in HighCharts

Hello I would like to ask how to properly instantiate and process a dynamically added series in Highcharts.

I am bringing about an instance of series like this:

var newSeries = new Highcharts.Series();
var newData = [];
date = Date.parse(newDate() +' UTC');
name = 'datapoint name';

newData.push([date, name]);

newSeries.name = 'Somename';

//newData variable processing
newSeries.data = newData;
newSeries.color = "#EEEEEE";
newSeries.showInLegend = false;
newSeries.index = -1;

chart.addSeries(newSeries);

With this code, I was able to add a new series in a Highchart object runtime. however, I would like to do some additional processing with my series object before adding it up to the actual chart.

I've tried:

newSeries.marker.enabled = "false";

newSeries.marker.states.hover = "false";

newSeries.index = -1; //to be able to send the series at the backmost part of the chart

but failed to achieve desired results.

If possible, can someone point me to the right direction on how to properly instantiate a series object with a marker object inside it? Any help would be very much appreciated.

EDIT: THE RIGHT ANSWER CARE OF GREG

Upvotes: 0

Views: 1047

Answers (1)

Greg Ross
Greg Ross

Reputation: 3498

If you add each point as an object then you have control over the markers as follows:

function addSeries(chart) {

        var newSeries = new Highcharts.Series();
        newSeries.name = 'Tokyo';
        newSeries.data = [{y: 1}, {y:20}, {y:23}, {y:11}];
        newSeries.zIndex = -1;

         for (var i = 0; i < newSeries.data.length; i++) {
             var datum = newSeries.data[i];
             datum.marker = {
                 enabled: false,
                 states: {
                     hover: {
                         enabled: false,
                         lineColor: '#ff0000'
                     }
                 }
            };
         }

        chart.addSeries(newSeries);     

    }

Here's a working example: http://jsfiddle.net/LrvB9/

Upvotes: 1

Related Questions