javascript - 如何修改Highcharts中的负轴条形图?

标签 javascript highcharts

我使用 Highcharts 创建了负轴条形图,但我希望的格式没有出现。我无法将其操作为所示的格式。

附上了我对下面提到的代码的输出。 http://jsfiddle.net/00bh7yp7/2/

// Age categories 
var categories = [
        '0-4', '5-9', '10-14', '15-19',
        '20-24', '25-29', '30-34', '35-39', '40-44',
        '45-49', '50-54', '55-59', '60-64', '65-69',
        '70-74', '75-79', '80-84', '85-89', '90-94',
        '95-99', '100 + ' ];

    Highcharts.chart('container', {
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Population pyramid for Germany, 2015'
        },
        subtitle: {
            text: 'Source: <a href="http://populationpyramid.net/germany/2015/">Population Pyramids of the World from 1950 to 2100</a>'
        },
        xAxis: {
            categories: categories,
            reversed: false,
            offset: 0,
            labels: {
                step: 1
            },

        },
        yAxis: {

            title: {
                text: null
            },
            labels: {
                formatter: function () {
                    return Math.abs(this.value) + '%';
                }
            }
        },

        plotOptions: {
            series: {
               stacking: 'normal'
            }
        },

        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + ', age ' + this.point.category + '</b><br/>' +
                    'Population: ' + Highcharts.numberFormat(Math.abs(this.point.y), 0);
            }
        },

        series: [{
            name: 'Male',
            data: [-2.2, -2.2, -2.3, -2.5, -2.7, -3.1, -3.2,
                -3.0, -3.2, -4.3, -4.4, -3.6, -3.1, -2.4,
                -2.5, -2.3, -1.2, -0.6, -0.2, -0.0, -0.0]
        }, {
            name: 'Female',
            data: [2.1, 2.0, 2.2, 2.4, 2.6, 3.0, 3.1, 2.9,
                3.1, 4.1, 4.3, 3.6, 3.4, 2.6, 2.9, 2.9,
                1.8, 1.2, 0.6, 0.1, 0.0]
        }] });

电流输出 enter image description here

所需输出 enter image description here

我只是在寻找格式,以便类别比例位于两个图表之间,然后我们可以进一步管理它。请帮忙。

最佳答案

实现该间距的一种方法是使用两个 y 轴,并使用 leftwidth 属性(它们没有记录在API,但它们可以工作):

  yAxis: [{
    left: '55%',
    width: '45%'
    (...)
  }, {
    reversed: true,
    width: '45%',
    offset: 0
    (...)
  }],
  series: [{
    data: [1, 3]
  }, {
    data: [2, 5],
    yAxis: 1
  }]

X 轴的处理方式类似:

  xAxis: {
    left: '50%',
    (...)
  }

现场演示: http://jsfiddle.net/kkulig/dx2vj8k1/

关于javascript - 如何修改Highcharts中的负轴条形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47645728/

相关文章:

javascript - 下拉列表中填充了数据库数据,并在按钮单击时添加

javascript - 使用 JavaScript 正则表达式进行全局匹配

javascript - Parse.com CloudCode 将用户添加到现有角色不起作用

javascript - Highcharts 时间数据具有不规则间隔且顺序错误

highcharts - 如何动态调用highcharts菜单项函数?

javascript - jQuery .text() 显示双文本

javascript - NivoSlider 在 magento 上运行不流畅

javascript - 在 highcharts 工具提示中附加第三个 `<td>` 值

javascript - Highcharts设置饼图切片大小

javascript - 更改Highchart堆积柱形图的样式