2013-05-08 37 views
1

我使用flot來繪製圖形。我想實現這樣的功能,使得我能夠突出顯示我的圖形中10%的增長,並以與現在使用的顏色不同的顏色顯示。 我使用的代碼是:使用flot api實施條形圖閾值

var options_blue = { 
    series: { 
     color: 'blue', 
     threshold: { above: 5, color: 'green' }, 
     bars: { show: true, barWidth: 20 * 20 } 
    }, 
    xaxis: { show: false, min: 1 }, 
    yaxis: { show: false, min: 1, max: max_value } 
}; 

var options_red = { 
    series: { 
     color: '#ff0000', 
     threshold: { above: 10, color:'green' },  
     bars: { show: true, barWidth: 20 * 20 } 
    }, 
    threshold: { above: 5, color: "yellow" }, 
    xaxis: { show: false, min: 1 }, 
    yaxis: { show: false, min: 5, max: max_value } 
}; 

我現在用的是jquery.flot.threshold.js,但在超過閾值的圖形的顏色沒有變化。

回答

3

您正在使用'above',但閾值插件僅支持'below'。所以你只需要交換你的系列和閾值顏色,並使用'下面'代替。

另請注意,在您的options_red中,系列選項之外還有第二個閾值選項。閾值插件僅在系列選項中查找選項,因此第二個選項將被忽略。

+0

我糾正了代碼中的錯誤。但我仍然無法使用jquery.flot.threshold.js繪製條形圖當我使用jquery.flot.threshold.min.js時,我可以繪製兩種不同的顏色,但圖形顯示爲單行。 爲此提供了任何可能的解決方案。 – 2013-05-09 05:18:13

+0

您需要提供更多信息; '你是什麼意思'出現一條線'?你使用的是什麼版本的Flot? JS控制檯中是否有錯誤? – DNS 2013-05-09 11:40:46