2015-02-08 144 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