Susanne92
Susanne92

Reputation: 217

Can I use different if-conditions in Highstock-code?

I want that my Highstock-Chart is very dynamic. I extract the number of series and yAxis from var dataarray. So I can get e.g. 2 series or 6 or 3 or or or...

But now I have to set the code for the yAxis and series according to the number of series that are arriving. And if dataarray is e.g. 2 long the program should jump in the accordingly if-condition.

But that doesn't work in real life. Here is my code. What can I do instead? Can't I use JavaScript in Highstock-Code?

highstock code

Upvotes: 0

Views: 1496

Answers (1)

Paweł Fus
Paweł Fus

Reputation: 45079

No you can't, and it's not because Highstock, but Javascript langauge.

When you create chart in that way:

new Highcharts.StokChart({
    //options
})

you are passing a literal { abc: something, xyz: somethineElse } where you can't put if-else conditions.

I think you can create something like this:

var xAxis,
    series;

if(x == 2) {
    xAxis = { /* options */ };
    series = [ /* options */ ];
} else {
    // something else
}

var chartName = new Highcharts.StockChart({
    xAxis: xAxis,
    series: series
});

Upvotes: 1

Related Questions