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

南笙酒味 提交于 2019-12-13 04:41:25

问题


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?


回答1:


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
});


来源:https://stackoverflow.com/questions/16838742/can-i-use-different-if-conditions-in-highstock-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!