2015-02-08 139 views
0

希望有人可以提供幫助,我已經搜索了這個示例,但無法讓他們在我的特定設置上工作。我在Highcharts中有一個堆疊柱形圖,代表一週中每天的5組數據。Highcharts - 堆棧圖到鑽取圖表中的堆棧圖

enter image description here

我再選擇一天看一天的每小時崩潰,我必須通過傳來的數據,但我不能讓5個值,我爲每個小時,在彼此疊放。 (以同樣的方式作爲第一圖表) - 理想地該第二圖表將是一個區域圖表)

enter image description here

這是我的代碼:

$(function() { 

    Highcharts.setOptions({ 
    lang: { 
     drillUpText: 'Reset' 
    } 
}); 

// Create the chart 
$('#chart2').highcharts({ 
    chart: { 
     type: 'column', 
     height: 300 
    }, 
    credits: { 
     enabled: false 
    }, 
    title: { 
     text: null 
    }, 
    subtitle: { 
     text: 'Select a day to expand to hourly data' 
    }, 

    legend: { 
      enabled: false 
     }, 


    tooltip: { 
     formatter: function() { 
      var point = this.point, 
       s = 'Day: <b>' + point.name + '</b><br/>Utilisation: <b>' + this.y + '% </b><br/>'; 
      if (point.drilldown) { 
       s = 'Day: <b>' + point.name + '</b><br/>Utilisation: <b>' + this.y + '% </b><br/>Select to view hours'; 
      } else { 
       s = 'Time: <b>' + point.name + '</b><br/>Utilisation: <b>' + this.y + '% </b><br/>Reset to return'; 
      } 
      return s; 
      } 

     }, 

    xAxis: { 
     type: 'category', 
     //categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], 
     //categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'] 
    }, 

    yAxis: { 
     title: false, // {text: 'Utilisation'}, Y axis title - taken text out 
     tickPositions: [0, 50, 70, 100], // Y axis labels 
     labels: { 
      format: '{value}%'  // Y axis labels with % suffix 
     }, 
     min: 0,      // Following lines setting the grids to off adding min max 
     max: 100, 
     minorGridLineWidth: 0, 
     gridLineWidth: 0, 
     alternateGridColor: null, 
     plotBands: [{ // Below Avg. 
      from: 0, 
      to: 50, 
      color: 'rgba(255,108,96, 0.5)', 
      label: { 
       // text: 'Below Average', 
       style: { 
        color: 'rgba(153,194,98, 0.8)' 
       } 
      } 
     }, { // Average 
      from: 50, 
      to: 70, 
      color: 'rgba(248,211,71, 0.5)', 
      label: { 
       // text: 'Average', 
       style: { 
        color: 'rgba(153,194,98, 0.8)' 
       } 
      } 
     }, { // Above Avg. 
      from: 70, 
      to: 100, 
      color: 'rgba(153,194,98, 0.5)', 
      label: { 
       text: 'Above Average', 
       style: { 
        color: 'rgba(153,194,98, 0.8)' 
       } 
      } 
     }] 
    }, 

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

    series: [{ 
     type: 'column', 
     name: 'Status 5', 
     color: '#86C9F2',  
     borderWidth: 0, 
     shadow: true, 
     data: [<?php echo $data7a5?>] 
    }, { 
     type: 'column', 
     name: 'Status 4', 
     color: '#6FB2DB', 
     borderWidth: 0, 
     shadow: true, 
     data: [<?php echo $data7a4?>] 
    }, { 
     type: 'column', 
     name: 'Status 3', 
     color: '#589BC4', 
     borderWidth: 0, 
     shadow: true, 
     data: [<?php echo $data7a3?>] 
    }, { 
     type: 'column', 
     name: 'Status 2', 
     color: '#4184AD', 
     borderWidth: 0, 
     shadow: true, 
     data: [<?php echo $data7a2?>] 
    }, { 
     type: 'column', 
     name: 'At the Desk', 
     color: '#2B6E97',   //rgb(43, 110, 151) 
     borderWidth: 0, 
     shadow: true, 
     data: [<?php echo $data7a?>] 
    }], 
    drilldown: { 
     drillUpButton: { 
      //relativeTo: 'spacingBox', 
      position: { 
       y: 10, 
       x: -10 
      }, 
     theme: { 
       fill: 'white', 
       stroke: 'silver', 
       r: 2, 
       states: { 
        hover: { 
         fill: '#41739D', 
         style: { 
          color: 'white' 
         } 
        } 
       } 
      } 
     }, 

     series: [{ 
      type: 'column', 
      id: 'D2', 
      data: [['8', 13.77],['8', 2.74],['8', 1.27],['8', 2.64],['8', 2.28],['9', 29.30],['9', 6.44],['9', 3.79],['9', 5.11],['9', 5.32],['10', 36.41],['10', 9.01],['10', 5.47],['10', 7.11],['10', 7.06],['11', 34.12],['11', 7.50],['11', 4.48],['11', 10.02],['11', 8.28],['12', 26.82],['12', 5.03],['12', 5.79],['12', 15.00],['12', 10.27],['13', 30.08],['13', 5.40],['13', 5.34],['13', 11.73],['13', 9.57],['14', 33.90],['14', 7.75],['14', 4.78],['14', 6.41],['14', 9.33],['15', 33.27],['15', 7.73],['15', 4.95],['15', 8.11],['15', 7.09],['16', 31.29],['16', 8.53],['16', 4.51],['16', 6.44],['16', 5.81],['17', 17.36],['17', 3.87],['17', 2.06],['17', 4.47],['17', 3.42],['18', 4.79],['18', .38],['18', .79],['18', 1.44],['18', 2.45]] 
     }, { 
      type: 'area', 
      id: 'D3', 
      data: [<?php echo $data7b2?>] 
     }, { 
      type: 'area', 
      id: 'D4', 
      data: [<?php echo $data7b3?>] 
     }, { 
      type: 'area', 
      id: 'D5', 
      data: [<?php echo $data7b4?>] 
     }, { 
      type: 'area', 
      id: 'D6', 
      data: [<?php echo $data7b5?>] 
     }] 
     } 
    }); 

});

我已經顯示了第一個向下鑽取數據,因此您可以看到結構。任何幫助,將不勝感激。

感謝 羅布

+0

你可以把它放在http://jsfiddle.net? – 2015-02-08 12:14:30

+0

而你正在使用** php **,所以請使用標籤。 – 2015-02-08 12:19:45

+0

嗨Raeen,我已經將代碼添加到JSFiddle,但是在我無法實現之前沒有使用它。這裏是鏈接雖然http://jsfiddle.net/robdwright/uxo2edzu/5/ – 2015-02-08 13:59:54

回答

0

您可以更改鑽取數據從['time', data][time, data]類型:

data: [ 
       ['8', 13.77], 
       ['8', 2.74], 
       ['8', 1.27], 
       ['8', 2.64], 
       ['8', 2.28], 
       ['9', 29.30], 
       ['9', 6.44], 
       ['9', 3.79], 
       ['9', 5.11], 
       ['9', 5.32], 
       ... 
] 

到:

data: [ 
       [8, 13.77], 
       [8, 2.74], 
       [8, 1.27], 
       [8, 2.64], 
       [8, 2.28], 
       [9, 29.30], 
       [9, 6.44], 
       [9, 3.79], 
       [9, 5.11], 
       [9, 5.32], 
       ... 
] 

而且我也改變了tooltip.formatter顯示正確的鑽取工具提示。這裏的DEMO

+0

Raeen,這非常棒 - 我不能相信這是當時的單引號!感謝您對工具提示的更新。 – 2015-02-09 09:00:31

+0

嗨Raeen,希望你能幫助這最後一塊。我一直在嘗試修改演示,並將鑽取堆棧的顏色添加爲與初始堆棧列相同的顏色。我爲Highcharts.setOptions代碼添加了一組顏色,例如顏色:['#2B6E97','#4184AD','#589BC4','#6FB2DB','#86C9F2'],也類似於深入系列,但沒有喜悅! – 2015-02-09 16:50:00

+1

我想我已經用settin gin plotOptions和colorByPoint算出了它,然後將顏色設置爲上面的註釋 - 現在鑽取的顏色正在工作 - 搞砸了初始堆棧,但我會到達那裏! – 2015-02-09 17:06:43