2012-03-22 76 views
5

請問我有一個頁面,在頁面中我有兩個餅圖, 我想爲2個圖表顯示不同的背景顏色,但它嵌入在CSS文件中! 有任何選擇使用任何顏色?或使其透明? 我的代碼:Jqplot餅圖的背景顏色

PieTimer[index] = jQuery.jqplot(PieTimerId, 

TimerValuesArray, 
{ 
seriesDefaults: { 

shadow: false, 

seriesColors: ["#13e837", "#6e869b"], 

renderer: jQuery.jqplot.PieRenderer, 

rendererOptions: { 

highlightMouseOver: false, 

diameter: 40, 

padding: 0, 

showDataLabels: false, 

startAngle: 270, 
sliceMargin: 0, 

shadowOffset: 0, 

shadowAlpha: 0, 


shadowDepth: 0, 

drawBorder: false, 

shadow: false, 

borderWidth: 0 

} 

}, 

legend: { show: false, location: 'w'} 

} 

); 

我想知道如果我可以設置一個屬性(例如:...的backgroundColor)繪製圖表時? 10x

回答

21

根據the jqPlot options page你有一個選項叫做grid你可以在其中設置所有的網格參數,其中一個參數是背景色。

grid: { 
    drawGridLines: true,  // wether to draw lines across the grid or not. 
    gridLineColor: '#cccccc', // *Color of the grid lines. 
    background: '#fffdf6',  // CSS color spec for background color of grid. 
    borderColor: '#999999',  // CSS color spec for border around grid. 
    borderWidth: 2.0,   // pixel width of border around grid. 
    shadow: true,    // draw a shadow for grid. 
    shadowAngle: 45,   // angle of the shadow. Clockwise from x axis. 
    shadowOffset: 1.5,   // offset from the line of the shadow. 
    shadowWidth: 3,    // width of the stroke for the shadow. 
    shadowDepth: 3,    // Number of strokes to make when drawing shadow. 
           // Each stroke offset by shadowOffset from the last. 
    shadowAlpha: 0.07,   // Opacity of the shadow 
    renderer: $.jqplot.CanvasGridRenderer, // renderer to use to draw the grid. 
    rendererOptions: {}   // options to pass to the renderer. Note, the default 
           // CanvasGridRenderer takes no additional options. 
}, 

使用的一個例子是:

var plot1 = jQuery.jqplot ('chart1', [data], 
{ 
    seriesDefaults: { 
     // Make this a pie chart. 
     renderer: jQuery.jqplot.PieRenderer 
    }, 
grid: { 
    drawGridLines: true,  // wether to draw lines across the grid or not. 
     gridLineColor: '#cccccc', // CSS color spec of the grid lines. 
     background: '#ffff66',  // CSS color spec for background color of grid. 
     borderColor: '#999999',  // CSS color spec for border around grid. 
     borderWidth: 2.0,   // pixel width of border around grid. 
     shadow: true,    // draw a shadow for grid. 
     shadowAngle: 45,   // angle of the shadow. Clockwise from x axis. 
     shadowOffset: 1.5,   // offset from the line of the shadow. 
     shadowWidth: 3,    // width of the stroke for the shadow. 
     shadowDepth: 3 
}, 
    legend: { show:true, location: 'e' } 
} 
); 

我希望它可以幫助你!

+1

這是解決方案,非常感謝。 我做到了以另一種方式,而這裏如果背景是一個圖像,它工作正常: 所有誰感興趣 我在js文件改變:jquery.jqplot.min.js以下 老:this.background =「#fffdf6」 新增功能:this.background =「透明」 可能如果我們在聖地亞哥提供的示例中放置tranparent,它也可以工作!再次感謝 – HGK 2012-03-22 14:27:51

+0

確認:背景:'透明'做你希望的。 – Tyler 2012-04-23 17:47:00

+3

修改分佈式.js文件本身並不具有良好的可維護性。我強烈建議不要遵循這個道路。 – 2012-04-28 03:18:30