Highcharts 3.0.8內建向下鑽取功能。在drilldown.series數組中,爲點進行向下鑽取設置就能夠實現。數組
基本設置app
基本設置中向下鑽取定義在 drilldown設置下的一個獨立的數組中。每個設置都會被分配ID,這樣咱們能夠使用它們爲鑽取的點進行識別。dom
效果圖:ssh
向下鑽取:異步
代碼:ide
series: [{ name: 'Things', colorByPoint: true, data: [{ name: 'Animals', y: 5, drilldown: 'animals' }, { name: 'Fruits', y: 2, drilldown: 'fruits' }, { name: 'Cars', y: 4, drilldown: 'cars' }] }], drilldown: { series: [{ id: 'animals', data: [ ['Cats', 4], ['Dogs', 2], ['Cows', 1], ['Sheep', 2], ['Pigs', 1] ] }, { id: 'fruits', data: [ ['Apples', 4], ['Oranges', 2] ] }, { id: 'cars', data: [ ['Toyota', 4], ['Opel', 2], ['Volkswagen', 2] ] }] }
異步設置ui
在修多狀況下,咱們都會想要其自動加載鑽取內容。設置 point.drilldown 爲true,並使用圖表向下鑽取選項加載基於點擊點的鑽取設置。當數據展示,咱們在呼出Chart.addSeriesAsDrilldown方式。this
效果圖:spa
對上圖中數據進行向下鑽取code
代碼:
$(function () { // Create the chart $('#container').highcharts({ chart: { type: 'column', events: { drilldown: function (e) { if (!e.seriesOptions) { var chart = this, drilldowns = { 'Animals': { name: 'Animals', data: [ ['Cows', 2], ['Sheep', 3] ] }, 'Fruits': { name: 'Fruits', data: [ ['Apples', 5], ['Oranges', 7], ['Bananas', 2] ] }, 'Cars': { name: 'Cars', data: [ ['Toyota', 1], ['Volkswagen', 2], ['Opel', 5] ] } }, series = drilldowns[e.point.name]; // Show the loading label chart.showLoading('Simulating Ajax ...'); setTimeout(function () { chart.hideLoading(); chart.addSeriesAsDrilldown(e.point, series); }, 1000); } } } }, title: { text: 'Async drilldown' }, xAxis: { type: 'category' }, legend: { enabled: false }, plotOptions: { series: { borderWidth: 0, dataLabels: { enabled: true, } } }, series: [{ name: 'Things', colorByPoint: true, data: [{ name: 'Animals', y: 5, drilldown: true }, { name: 'Fruits', y: 2, drilldown: true }, { name: 'Cars', y: 4, drilldown: true }] }], drilldown: { series: [] } }) });
有數據狀況效果圖:
無數顯示No data to display
代碼:
$(function () { var chart, btnRemove = $('#remove'), btnAdd = $('#add'); btnAdd.click(function () { chart.series[0].addPoint(Math.floor(Math.random() * 10 + 1)); // Return random integer between 1 and 10. }); btnRemove.click(function () { if(chart.series[0].points[0]) { chart.series[0].points[0].remove(); } }); $('#container').highcharts({ chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false }, title: { text: 'No data in pie chart' }, series: [{ type: 'pie', name: 'Random data', data: [] }] }); chart = $('#container').highcharts(); });
效果圖:
代碼:
$(function () { $('#container').highcharts({ title: { text: 'Non-snapped crosshair' }, xAxis: { crosshair: { snap: false } }, yAxis: { crosshair: { snap: false } }, series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] }] }); });