带有线条的柱形图 - 组合图表自定义

时间:2018-05-31 09:38:23

标签: javascript linechart column-chart jscharts

a busy cat

哪个JS库最适合做上述类型的图表?

我想将聚集柱形图与折线图结合起来,如上图所示。

我的要求是每列应设置低值和高值

1 个答案:

答案 0 :(得分:4)

请使用highcharts。 请参考JSFiddle获取代码

$(function () {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: "container",
            type: "column"

        },
        plotOptions: {
            series: {
                pointWidth: 25
            },
            line: {
                marker: {
                    type: 'dot'
                }
            }
        },
        title: {
            text: null
        },
        series: [{ "name": "india", "data": [{ y: 1, color: 'red' }, { y: 3, color: '#f99820' }, { y: 3, color: '#f1da37' }, { y: 2, color: '#965129' }] },
        {"name": "usa", "data": [0, 0, 0, 0, { y: 3, color: 'red' }, { y: 2, color: '#f99820' }, { y: 3, color: '#f1da37' }, { y: 1, color: '#965129' }] },
        { "name": "china", "data": [0, 0, 0, 0, 0, 0, 0, 0, { y: 3, color: 'red' }, { y: 2, color: '#f99820' }, { y: 3.1, color: '#f1da37' }, { y: 1.9, color: '#965129' }]}, { "name": "target", "data": [3, 1, 3, 2, 2, 1, 1.9, 2.4, 2.8, 1.9, 2.9, 1.6], yAxis: 1, type: 'line' },
        { "name": "baseline", "data": [1.3, .1, 1.3, 0, 1.2, .5, 1.2, .2, .5, 1.2, 2.1, .2], yAxis: 1, type: 'line' }],
        xAxis: {
            categories: [{ "name": "india", "categories": ["june 2016", "july 2016", "august 2016", "september 2016"] }, { "name": "usa", "categories": ["may 2017", "june 2016", "july 2016", "august 2016"] }, { "name": "china", "categories": ["may 2017", "june 2017", "july 2017", "august 2017"] }]
        },
        yAxis: [{ // Primary yAxis
            labels: {
                format: '{value}',
                style: {
                    color: '#89A54E'
                }
            }
        }, ,
            labels: {
                format: '',
                style: {
                    color: '#4572A7'
                }
            },
            opposite: true
        }],
    });
});