在第2次和第3次向下钻取的图例中创建新值

时间:2018-03-27 07:51:20

标签: highcharts legend drilldown

我已经创建了图3级精简版,并想要显示第3级跟随颜色的图例。



Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Stacked bar chart'
    },
    xAxis: {
      labels: {
        rotation: -45,
        align: "right",
        y: 30,
      },
      type: "category",
      tickWidth: 0
    },
    yAxis: {
        title: {
            text: 'Total fruit consumption'
        }
    },
    legend: {
      enabled: true,
      itemStyle: {
        fontSize:'10px'
      },
      align: 'right',
      verticalAlign: 'middle',
      layout: 'vertical',
      reversed:true

    },
    plotOptions: {
							
      series: {
        cropThreshold: 1000,
        animation: {
          duration: 300
        },
        cursor: 'pointer',
        point: {
          events: {
            click: function () {
              if(this.id)
              {
                alert(this.id);
              }
            }
          }
        }
      },
      column: {
        cropThreshold: 1000,
        minPointLength: 3,
        animation: false,
        stacking: 'normal'
      }
    },
    series: [{
              index: 0,
              name: 'Tippers',
              turboThreshold: 0,
              cropThreshold: Infinity,
              data: [{
                        name:'01-Feb-2018',
                        colorByPoint:true,
                        y:3,
                        drilldown:'Tippers-1-2-2018'
                      }]
            }],
     drilldown: {
							activeAxisLabelStyle: {
                textDecoration: 'none',
                color: 'black',
                fontWeight: 'normal'
              },
              series: [{
                          name: '01-Feb-2018',
                          id: 'Tippers-1-2-2018',
                          turboThreshold: 0,
                          cropThreshold: Infinity,
                          showInLegend: false,
                          data: [ {
                                    name: 'psb04221',
                                    y: 1,
                                    drilldown:'psb04221/Tippers-1-2-2018'
                                    },{
                                    name: 'rvd910939',
                                    y: 2,
                                    drilldown:'rvd910939/Tippers-1-2-2018'
                                    },]
                      },{
                          name: '01-Feb-2018',
                          id: 'Trucks-1-2-2018',
                          turboThreshold: 0,
                          cropThreshold: Infinity,
                          showInLegend: false,
                          data: [ {
                                    name: 'rvd910939',
                                    y: 2,
                                    drilldown:'rvd910939/Trucks-1-2-2018'
                                    },{
                                    name: 'sks913031',
                                    y: 1,
                                    drilldown:'sks913031/Trucks-1-2-2018'
                                    },]
                      },{
                          name: 'psb04221 / Tippers 1-February-2018',
                          id: 'psb04221/Tippers-1-2-2018',
                          turboThreshold: 0,
                          cropThreshold: Infinity,
                          showInLegend: false,
                          data: [ {
                            name: '01-February-2018-44',
                            id: '44',
                            y: 1,
                            type_legend: 'green',
                            color:'green'
                         
                          },]
                        },{
                          name: 'rvd910939 / Tippers 1-February-2018',
                          id: 'rvd910939/Tippers-1-2-2018',
                          turboThreshold: 0,
                          cropThreshold: Infinity,
                          showInLegend: false,
                          data: [ {
                            name: '01-February-2018-21',
                            id: '21',
                            y: 1,
                            type_legend: 'green',
														color:'green'
                          },{
                            name: '01-February-2018-25',
                            id: '25',
                            y: 1,
                            type_legend: 'yellow',
                            color:'yellow'
                          },{
                            name: '01-February-2018-27',
                            id: '27',
                            y: 1,
                            type_legend: 'green',
														color:'green'
                         
                          },]
                        },{
                          name: 'rvd910939 / Trucks 1-February-2018',
                          id: 'rvd910939/Trucks-1-2-2018',
                          turboThreshold: 0,
                          cropThreshold: Infinity,
                          showInLegend: false,
                          data: [ {
                            name: '01-February-2018-13',
                            id: '13',
                            y: 1,
                            type_legend: 'red',
                            color:'red'
                          },{
                            name: '01-February-2018-26',
                            id: '26',
                            y: 1,
                            type_legend: 'green',
                            color:'green'
                          },]
                        },{
                          name: 'sks913031 / Trucks 1-February-2018',
                          id: 'sks913031/Trucks-1-2-2018',
                          turboThreshold: 0,
                          cropThreshold: Infinity,
                          showInLegend: false,
                          data: [ {
                            name: '01-February-2018-22',
                            id: '22',
                            y: 1,
                            type_legend: 'yellow',
                            color:'yellow'
                          },{
                            name: '01-February-2018-23',
                            id: '23',
                            y: 1,
                            type_legend: 'green',
                            color:'green'
                          },]
                        }]
							}
});

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
&#13;
&#13;
&#13;

第一次向下钻取图例显示日期正确

第二次深入研究我想展示传奇用户

第3次深入研究我想显示滤色器的图例

请帮助我为第3次下钻的红色,​​绿色和蓝色添加显示图例过滤器的图例,如下图所示:3rd Drilldown

1 个答案:

答案 0 :(得分:0)

我已经通过ppotaczek的回答解决了问题。

在您的示例中,第三级深入分析是一个系列,这就是图例仅显示一个项目的原因。如果要在向下钻取时有多个图例项,则必须具有多个系列。您可以使用drilldown事件和addSeriesAsDrilldown方法,如下例所示,以获得所需的结果。

现场演示:http://jsfiddle.net/BlackLabel/amg8234t/

API参考:

https://api.highcharts.com/class-reference/Highcharts.Chart#addSeriesAsDrilldown

https://api.highcharts.com/highcharts/chart.events.drilldown

祝你好运!

非常感谢你。