深入研究面积图

时间:2018-07-31 09:33:27

标签: angular ionic-framework highcharts

如何使用ionic 3和angular来实现高图中的面积图的向下钻取?有人可以帮忙吗?谷歌上没有与此相关的东西。高级图表库目前仅支持对柱状图,饼形图和条形图的向下钻取。您还能介绍一下如何在面积图中实现异步向下钻取吗?

有人对此有任何想法吗?会很有帮助。

下面是我的同步钻取代码。向下钻取没有发生。您能指出代码有什么问题吗?

chartOptions : any;
  // reorder: boolean = false;
  // @ViewChild('select') select: any;
  constructor(public navCtrl: NavController) {
    // this.menu.enable(true, 'app-menu');



      this.chartOptions = {
        chart: {
          type: 'area',
        },
      title: {
          text: 'Operations'
      },
      xAxis: {
        allowDecimals: false,
        labels: {
            formatter: function () {
                return this.value; // clean, unformatted number for year
            }
        }
    },
    yAxis: {
        title: {
            text: 'Nuclear weapon states'
        },
        labels: {
            formatter: function () {
                return this.value / 1000 + 'k';
            }
        }
    },
    tooltip: {
        pointFormat: '{series.name} had stockpiled <b>{point.y:,.0f}</b><br/>warheads in {point.x}'
    },
    plotOptions: {
        area: {
            pointStart: 1940,
            marker: {
                enabled: false,
                symbol: 'circle',
                radius: 2,
                states: {
                    hover: {
                        enabled: true
                    }
                }
            }
        }
    },
    series: [{
        name: 'USA',
        trackByArea: true,
        data: [{
          y: null,
          drilldown: 'driller'
        }, {
          y: null,
          drilldown: 'driller'
        }, {
          y: null,
          drilldown: 'driller'
        },
        {   y: null,
            drilldown: 'driller'
          }, {
            y: null,
            drilldown: 'driller'
          }, {
            y: 6,
            drilldown: 'driller'
          }, {
            y: 11,
            drilldown: 'driller'
          },{
            y: 32,
            drilldown: 'driller'
          }, {
            y: 110,
            drilldown: 'driller'
          }, {
            y: 235,
            drilldown: 'driller'
          }, {
            y: 369,
            drilldown: 'driller'
          }, {
            y: 640,
            drilldown: 'driller'
          },{
            y: 1005,
            drilldown: 'driller'
          }, {
            y: 1436,
            drilldown: 'driller'
          }, {
            y: 2063,
            drilldown: 'driller'
          }, {
            y: 3057,
            drilldown: 'driller'
          },{
            y: 4618,
            drilldown: 'driller'
          }, {
            y: 6444,
            drilldown: 'driller'
          }, {
            y: 9822,
            drilldown: 'driller'
          }, {
            y: 15468,
            drilldown: 'driller'
          },{
            y: 20434,
            drilldown: 'driller'
          }, {
            y: 24126,
            drilldown: 'driller'
          }, {
            y: 27387,
            drilldown: 'driller'
          }, {
            y: 29459,
            drilldown: 'driller'
          }, {
            y: 27387,
            drilldown: 'driller'
          }, {
            y: 29459,
            drilldown: 'driller'
          },{ 
            y: 32040,
            drilldown: 'driller'
          }, {
            y: 31233,
            drilldown: 'driller'
          },{
            y: 29224,
            drilldown: 'driller'
          }, {
            y: 27342,
            drilldown: 'driller'
          }, {
            y: 26662,
            drilldown: 'driller'
          }, {
            y: 26956,
            drilldown: 'driller'
          },{
            y: 27912,
            drilldown: 'driller'
          }, {
            y: 28999,
            drilldown: 'driller'
          }, {
            y: 28965,
            drilldown: 'driller'
          }, {
            y: 27826,
            drilldown: 'driller'
          },{
            y: 25579,
            drilldown: 'driller'
          }, {
            y: 25722,
            drilldown: 'driller'
          }, {
            y: 24826,
            drilldown: 'driller'
          },{
            y: 24605,
            drilldown: 'driller'
          }, {
            y: 24304,
            drilldown: 'driller'
          }, {
            y: 23464,
            drilldown: 'driller'
          }, {
            y: 23708,
            drilldown: 'driller'
          },{
            y: 24099,
            drilldown: 'driller'
          }, {
            y: 24357,
            drilldown: 'driller'
          }, {
            y: 24237,
            drilldown: 'driller'
          }, {
            y: 24401,
            drilldown: 'driller'
          },{
            y: 24344,
            drilldown: 'driller'
          }, {
            y: 23586,
            drilldown: 'driller'
          }, {
            y: 22380,
            drilldown: 'driller'
          }, {
            y: 21004,
            drilldown: 'driller'
          },{
            y: 17287,
            drilldown: 'driller'
          }, {
            y: 14747,
            drilldown: 'driller'
          }, {
            y: 13076,
            drilldown: 'driller'
          }, {
            y: 12555,
            drilldown: 'driller'
          },{
            y: 12144,
            drilldown: 'driller'
          }, {
            y: 11009,
            drilldown: 'driller'
          }, {
            y: 10950,
            drilldown: 'driller'
          }, {
            y: 10871,
            drilldown: 'driller'
          },{
            y: 10824,
            drilldown: 'driller'
          }, {
            y: 10577,
            drilldown: 'driller'
          }, {
            y: 10527,
            drilldown: 'driller'
          }, {
            y: 10475,
            drilldown: 'driller'
          },{
            y: 10421,
            drilldown: 'driller'
          }, {
            y: 10358,
            drilldown: 'driller'
          }, {
            y: 10295,
            drilldown: 'driller'
          }, {
            y: 10104,
            drilldown: 'driller'
          },{
            y: 9914,
            drilldown: 'driller'
          }, {
            y: 9620,
            drilldown: 'driller'
          }, {
            y: 9326,
            drilldown: 'driller'
          }, {
            y: 5113,
            drilldown: 'driller'
          },{
            y: 5113,
            drilldown: 'driller'
          }, {
            y: 4954,
            drilldown: 'driller'
          }, {
            y: 4804,
            drilldown: 'driller'
          }, {
            y: 4761,
            drilldown: 'driller'
          }, {
            y: 4717,
            drilldown: 'driller'
          },{
            y: 4368,
            drilldown: 'driller'
          }, {
            y: 4018,
            drilldown: 'driller'
          }]


    }, {
        name: 'USSR/Russia',
        data: [null, null, null, null, null, null, null, null, null, null,
            5, 25, 50, 120, 150, 200, 426, 660, 869, 1060,
            1605, 2471, 3322, 4238, 5221, 6129, 7089, 8339, 9399, 10538,
            11643, 13092, 14478, 15915, 17385, 19055, 21205, 23044, 25393, 27935,
            30062, 32049, 33952, 35804, 37431, 39197, 45000, 43000, 41000, 39000,
            37000, 35000, 33000, 31000, 29000, 27000, 25000, 24000, 23000, 22000,
            21000, 20000, 19000, 18000, 18000, 17000, 16000, 15537, 14162, 12787,
            12600, 11400, 5500, 4512, 4502, 4502, 4500, 4500
        ]
    }],
    drilldown: {
        series: [{
          name: 'Driller series',
          data: [1, 2, 3, 4, 1, 6, 7, 8],
          id: 'driller'
        }]
    }
    }

}
}

HTML code:
<ion-content>
    <chart [options] = "chartOptions" style="display: block" type = "chart"> </chart>
 </ion-content>

1 个答案:

答案 0 :(得分:0)

可以通过以下方式对面积图进行下钻:

设置drilldown for each point,然后启用trackByArea(我们启用了此功能,以便我们可以单击系列中间的内容,但仍会被向下钻取):

series: [{
  name: 'Series 1',
  trackByArea: true,
  data: [{y: 1, drilldown: 'drilldownseries'}, 
         {y: 2, drilldown: 'drilldownseries'},
         ...
        ]
  }]

然后添加drilldown series

drilldown: {
  series: [{
    name: 'Driller series',
    data: [1, 2, 3, ...],
    id: 'drilldownseries'
  }]
}

请确保包括drilldown.js,如果没有该模块,则无法在高级图表中进行细化。

工作中的JSFiddle示例: http://jsfiddle.net/ewolden/uaLmg51k/