【问题标题】:Drilldown operation in Column-Stacked Bar diagram HighCharts列堆叠条形图 HighCharts 中的向下钻取操作
【发布时间】:2020-06-19 17:26:53
【问题描述】:

我有一个类似的条形图

https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/column-stacked/

而且我需要以这样一种方式显示向下钻取,即在下一页中将单个列拆分为多个条。

例如: 如果我单击栏中的 Apples 列,它应该向下钻取到具有 3 列的下一页

  • 第一列 - x 轴:Joe,y 轴:3
  • 第二列 - x 轴:简,y 轴:2
  • 第三列 - x 轴:John,y 轴:5

主条形图中其余列的类似操作。 最后,我应该也可以导航回主页了。

任何人的帮助将不胜感激。提前致谢。

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Stacked column chart'
    },
    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Total fruit consumption'
        },
        stackLabels: {
            enabled: true,
            style: {
                fontWeight: 'bold',
                color: ( // theme
                    Highcharts.defaultOptions.title.style &&
                    Highcharts.defaultOptions.title.style.color
                ) || 'gray'
            }
        }
    },
    legend: {
        align: 'right',
        x: -30,
        verticalAlign: 'top',
        y: 25,
        floating: true,
        backgroundColor:
            Highcharts.defaultOptions.legend.backgroundColor || 'white',
        borderColor: '#CCC',
        borderWidth: 1,
        shadow: false
    },
    tooltip: {
        headerFormat: '<b>{point.x}</b><br/>',
        pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            dataLabels: {
                enabled: true
            }
        }
    },
    series: [{
        name: 'John',
        data: [5, 3, 4, 7, 2]
    }, {
        name: 'Jane',
        data: [2, 2, 3, 2, 1]
    }, {
        name: 'Joe',
        data: [3, 4, 4, 2, 5]
    }]
});
<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>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Chart showing stacked columns for comparing quantities. Stacked charts
        are often used to visualize data that accumulates to a sum. This chart
        is showing data labels for each individual section of the stack.
    </p>
</figure>

【问题讨论】:

    标签: javascript html css highcharts jinja2


    【解决方案1】:

    您的要求可以通过以适当的方式配置数据并添加钻取模块来实现。

    演示:https://jsfiddle.net/BlackLabel/xz46uspb/

    系列数据示例:

      series: [{
        name: 'John',
        data: [{
          y: 5,
          name: 'Apples',
          drilldown: "Apples"
        }, {
          y: 3,
          name: 'Oranges',
          drilldown: "Oranges"
        }, {
          y: 4,
          name: 'Pears',
          drilldown: "Pears"
        }]
      }, ...
    ],
    

    以及向下钻取数据:

      drilldown: {
        series: [{
          name: 'Apples',
          id: 'Apples',
          colorByPoint: true,
          data: [{
            name: 'John',
            y: 5
          }, {
            name: 'Jane',
            y: 2
          }, {
            name: 'Joe',
            y: 3
          }]
        }]
      }
    

    API:https://api.highcharts.com/highcharts/xAxis.type

    API:https://api.highcharts.com/highcharts/series.column.colorByPoint

    API:https://api.highcharts.com/highcharts/drilldown

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-07
      • 2023-03-11
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多