Highcharts中的if语句

Highcharts中的if语句,highcharts,Highcharts,我想根据图例的'align'选项动态反转图例顺序,但我是javascript的初学者,我不知道它会是什么样子 如果图例的对齐设置为“左”或“右”,则我希望将图例的“反转”选项设置为“真”,否则设置为“假” 以下是我的jsfillde: 在python中,我将执行以下操作: if legend align == “left” or “right”: legend reverse = true else: legend reverse = false 您需要在图表配置对象之外使

我想根据图例的'align'选项动态反转图例顺序,但我是javascript的初学者,我不知道它会是什么样子

如果图例的对齐设置为“左”或“右”,则我希望将图例的“反转”选项设置为“真”,否则设置为“假”

以下是我的jsfillde:

在python中,我将执行以下操作:

if legend align == “left” or “right”:
     legend reverse = true
else:
     legend reverse = false

您需要在图表配置对象之外使用
if-else
语句:

var options = {
    legend: {
        align: 'right',
        ...
    },

    ...
}

if (
    options.legend.align === 'left' ||
    options.legend.align === 'right'
) {
    options.legend.reversed = true;
} else {
    options.legend.reversed = false;
}

Highcharts.chart('container', options);
现场演示:

相关问题: