2016-04-28 74 views
0

是否可以自定義Highcharts方塊圖的圖表來標記而不是方框。我需要創造一個脾臟和盒子之間交叉的東西。我試圖用錯誤的酒吧例子搞亂,但不能讓花線不失標記被隱藏:http://jsfiddle.net/ryfqwska/我試圖創建此:enter image description hereHighcharts方塊圖自定義

$(function() { 
    $('#container').highcharts({ 
     chart: { 
      zoomType: 'xy' 
     }, 
     title: { 
      text: 'Temperature vs Rainfall' 
     }, 
     plotOptions: { 
      series: { 
       lineWidth: 1 
      } 
     }, 
     xAxis: [{ 
      categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
     }], 
     yAxis: [{ // Primary yAxis 
      labels: { 
       format: '{value} °C', 
       style: { 
        color: Highcharts.getOptions().colors[1] 
       } 
      }, 
      title: { 
       text: 'Temperature', 
       style: { 
        color: Highcharts.getOptions().colors[1] 
       } 
      } 
     }, { // Secondary yAxis 
      title: { 
       text: 'Rainfall', 
       style: { 
        color: Highcharts.getOptions().colors[0] 
       } 
      }, 
      labels: { 
       format: '{value} mm', 
       style: { 
        color: Highcharts.getOptions().colors[0] 
       } 
      }, 
      opposite: true 
     }], 

     tooltip: { 
      shared: true 
     }, 

     series: [{ 
      name: 'Rainfall error', 
      type: 'errorbar', 
      yAxis: 1, 
      data: [[48, 51], [68, 73], [92, 110], [128, 136], [140, 150], [171, 179], [135, 143], [142, 149], [204, 220], [189, 199], [95, 110], [52, 56]], 
      tooltip: { 
       pointFormat: '(error range: {point.low}-{point.high} mm)<br/>' 
      } 
     }, { 
      name: 'Temperature', 
      type: 'spline', 
      data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6], 
      tooltip: { 
       pointFormat: '<span style="font-weight: bold; color: {series.color}">{series.name}</span>: <b>{point.y:.1f}°C</b> ' 
      } 
     }, { 
      name: 'Temperature error', 
      type: 'errorbar', 
      data: [[6, 8], [5.9, 7.6], [9.4, 10.4], [14.1, 15.9], [18.0, 20.1], [21.0, 24.0], [23.2, 25.3], [26.1, 27.8], [23.2, 23.9], [18.0, 21.1], [12.9, 14.0], [7.6, 10.0]], 
      tooltip: { 
       pointFormat: '(error range: {point.low}-{point.high}°C)<br/>' 
      } 
     }] 
    }); 
}); 

回答

1

在你花系列,顏色設置爲'白色',然後將標記填充顏色設置爲其他內容。這將隱藏線條,僅顯示標記,並正確更新圖例。

name: 'Temperature', 
type: 'spline', 
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6], 
color: 'white', /* hides the line */ 
marker: { fillColor: 'red'}, /* reveals the markers only */ 
tooltip: { 
    pointFormat: '<span style="font-weight: bold; color: {series.color}">{series.name}</span>: <b>{point.y:.1f}°C</b> ' 
} 

又見小提琴在:http://jsfiddle.net/brightmatrix/ryfqwska/1/

我希望這有助於!

enter image description here

+1

謝謝。我將顏色設置爲透明,並且做到了這一點。 – neridaj

+0

啊,我忘了透明設置!我很高興爲您解決問題,並感謝您的改進。 –