如何在默认情况下将series-label设置为false,并在highchart中更改系列标签文本的颜色

Sim*_*ons 2 javascript jquery highcharts timeserieschart

我的页面上有5个高级图表,我只需要一个图表中的系列标签.

但是在我加入的那一刻series-label.js,它为所有图表添加了系列标签.

另外,如何更改系列标签的颜色.例如,在下面的示例中,我需要所有系列标签都是黑色.

Highcharts.chart('container', {
    chart: {
        type: 'line'
    },   
    series: [
    {
        name: 'Unites States',
        data: [7.5, 15.2, 18.7, 21.5, 25.9, 30.2, 29.0, 28.6, 27.2, 20.3, 18.6, 14.8]
    },
    {
        name: 'Tokyo',
        data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
    }, {
        name: 'London',
        data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
    }]
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Run Code Online (Sandbox Code Playgroud)

ewo*_*den 5

Highcharts在每个系列的基础上隐藏标签的方法是使用API.要隐藏图表中所有系列的标签,可以执行以下操作(API):

plotOptions: {
  series: {
    label: {enabled: false},
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

同样,要更改系列的标签颜色,可以使用API,或更改图表(API)中所有系列的颜色:

plotOptions: {
  series: {
    label: {style: {color: 'black'}},
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

这导致了这个例子:

Highcharts.chart('container', {
    chart: {
        type: 'line'
    },
    title: { text: 'No labels' },
    plotOptions: {
      series: {
        label: {
          enabled: false
        }
      }
    },
    series: [
    {
        name: 'Unites States',
        data: [7.5, 15.2, 18.7, 21.5, 25.9, 30.2, 29.0, 28.6, 27.2, 20.3, 18.6, 14.8]
    },
    {
        name: 'Tokyo',
        data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
    }, {
        name: 'London',
        data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
    }]
});

Highcharts.chart('container2', {
    chart: {
        type: 'line',
    },
    title: { text: 'Black labels' },
    plotOptions: {
      series: {
        label: {
          style: {
            color: 'black'
          }
        }
      }
    },
    series: [
    {
        name: 'Unites States',
        data: [7.5, 15.2, 18.7, 21.5, 25.9, 30.2, 29.0, 28.6, 27.2, 20.3, 18.6, 14.8]
    },
    {
        name: 'Tokyo',
        data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
    }, {
        name: 'London',
        data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
    }]
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<div id="container2" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
Run Code Online (Sandbox Code Playgroud)

  • 看起来不错,解决了实际问题.我会放弃一个小提琴,我将全局默认设置为'false`,如果有很多图表可以单独禁用,这可能是值得的:[JSFiddle](http://jsfiddle.net/zuspdm2L/3/) (2认同)