用Highcharts的简单系列柱形图的图例控制列

时间:2018-06-21 13:19:10

标签: javascript highcharts

(可能是How to create a single series bar graph with Highcharts的副本)

我正在尝试创建一个简单的Highcharts柱形图,其中在图例中具有单个系列和多个标签,如下所示

UI for series bar chart

通过切换图例(系列1)可以显示和隐藏两个柱形图。我需要使用图例(应标记为Jan和Feb)来控制各个列

供参考的代码段-

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Monthly Average Temperature'
    },
    subtitle: {
        text: 'Source: WorldClimate.com'
    },
    xAxis: {
        categories: ['Jan', 'Feb' ]
        
    },
    yAxis: {
        title: {
            text: 'Temperature (°C)'
        }
    },
    plotOptions: {
        line: {
            dataLabels: {
                enabled: true
            },
            enableMouseTracking: false
        }
    },
    
    series: [
        {
            data: [
                {y: 6, name: 'First', color: 'blue'},
                {y: 6, name: 'sec', color: 'red'}
            ]
        }
    ]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.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>

0 个答案:

没有答案