简体   繁体   English

是否可以在一个Highcharts图表中合并两个柱形图?

[英]Is it possible to combine two column charts in a single Highcharts chart?

Highcharts supports combining different types of charts, eg combining a spline with a column in a single chart. Highcharts支持组合不同类型的图表,例如在单个图表中组合样条曲线和列。 And of course one can combine multiple splines in the same chart. 当然,可以在同一张图表中组合多个样条曲线。 Is it possible to combine multiple columns? 是否可以合并多个列? Can I combine a column chart with a second column chart, ie to have one set of columns displayed on top (via zIndex) of another set of columns? 我可以将柱形图与第二个柱形图结合使用,即在另一组柱形的顶部(通过zIndex)显示一组柱形吗?

This fiddle -- http://jsfiddle.net/Bridgeland/rqrQ4/ --- shows the simplest possible example. 这个小提琴-http: //jsfiddle.net/Bridgeland/rqrQ4/-显示了最简单的示例。 I wanted to have a short squat yellow rectangle on top (zIndex) of a tall, skinny red rectangle, with the yellow rectangle covering up the bottom half of the red rectangle. 我想在一个细长的红色矩形的顶部(zIndex)上有一个矮矮的黄色矩形,黄色矩形覆盖红色矩形的下半部分。 Instead they appear side by side. 相反,它们并排出现。

在此处输入图片说明

Is what I want possible in Highcharts? 我想要在Highcharts中实现什么?

(And as an aside, why does Highcharts cut the width of both columns in half? If the chart has only the series for the red rectangle, it is 5000 wide instead of 2500, and if the chart has only the series for the yellow rectangle, it is 10000 wide instead of 5000.) (顺便说一句,为什么Highcharts会将两列的宽度都减半?如果图表只有红色矩形的序列,那么它的宽度是5000,而不是2500,并且图表只有黄色矩形的序列,它的宽度是10000,而不是5000。)

Here's the code corresponding to the fiddle: 这是与小提琴相对应的代码:

$(function () {
    $('#container').highcharts({
        chart: { 
            alignTicks: false
        },
        title: {
            text: ""
        },
        yAxis: {
            min: 0,
            max: 1
        },
        xAxis: {
            min: 0,
            endOnTick: false,  
            max: 9000
        },
        legend: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        series: [

        {
            data: [
            1],
            type: "column",
            pointPadding: 0.01,
            groupPadding: 0,
            color: "red",
            pointInterval: 5000,
            pointRange: 5000,
            borderWidth: 0,
            shadow: false,
            pointPlacement: "between",
            zIndex: 0,
            minPointLength: 3
        }, {
            data: [
            0.5],
            type: "column",
            pointPadding: 0.01,
            groupPadding: 0,
            color: "yellow",
            pointInterval: 10000,
            pointRange: 10000,
            borderWidth: 0,
            shadow: false,
            pointPlacement: "between",
            zIndex: 1,
            minPointLength: 3
        }]
    })
})

Remove groupPadding and set: 删除groupPadding并设置:

plotOptions: {
  series: {
    grouping: false
  }
}

And live example: http://jsfiddle.net/rqrQ4/1/ 和现场示例: http : //jsfiddle.net/rqrQ4/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM