2016-11-06 95 views
0

我正在做簡單的甜甜圈圖表,這些圖表的行爲更像是有規律的,因爲它們在系列中有一個單一的數據點並不能滿足整個數據點。目前,我正在將第二個數據點放入系列作爲空白區域,但這具有需要隱藏工具提示和高亮顯示的所有缺陷。什麼是最好的方法呢?我認爲我可以設置圖表的總價值,但我無法在任何地方的文檔中找到它。高級甜甜圈圖表沒有所有的切片

回答

1

餡餅系列總價值是通過總和所有點的價值計算得出的。

因此,根據您的積分值和切片的大小,添加第二個點,使其不可見並將ignoreHiddenPoint設置爲false。

series: [{ 
    type: 'pie', 
    name: 'Brands', 
    colorByPoint: true, 
    ignoreHiddenPoint: false, 
    data: [ 
    { 
    y: 50, 
    visible: false 
    }, 
    50] 
}] 

例如:http://jsfiddle.net/41xqpnzf/1/

可選地,可以改變updateTotals()行爲並且將其擴展,所以可以設置一個固定的總價值。

Highcharts.seriesTypes.pie.prototype.updateTotals = function() { 
var i, 
    total = 0, 
    points = this.points, 
    len = points.length, 
    point, 
    ignoreHiddenPoint = this.options.ignoreHiddenPoint, 
    fixedTotal = this.options.fixedTotal; 

if (!Highcharts.isNumber(fixedTotal) || fixedTotal < 0) { 
    // Get the total sum 
    for (i = 0; i < len; i++) { 
    point = points[i]; 
    // Disallow negative values (#1530, #3623, #5322) 
    if (point.y < 0) { 
     point.y = null; 
    } 
    total += (ignoreHiddenPoint && !point.visible) ? 0 : point.y; 
    } 
} else { 
    total = fixedTotal; 
} 

this.total = total; 

// Set each point's properties 
for (i = 0; i < len; i++) { 
    point = points[i]; 
    point.percentage = (total > 0 && (point.visible || !ignoreHiddenPoint)) ? point.y/total * 100 : 0; 
    point.total = total; 
} 
}; 

然後在選項

series: [{ 
    type: 'pie', 
    name: 'Brands', 
    fixedTotal: 100, 
    colorByPoint: true, 
    data: [50] 
}] 

例如:http://jsfiddle.net/41xqpnzf/2/

Highcharts也有一個計圖表,所以也許這是你在找什麼 - 沒有調整的餅圖。