2016-10-05 12 views
1

棒グラフのコードをjqplotを使って書いています。棒グラフの柱に異なる色が表示されない

問題:すべての3つのデータ(最初の色)に1つの色しか表示されない ダニの色をどのように表示するのですか?

$(document).ready(function(){ 
$.jqplot.config.enablePlugins = true; 


var d1=${likes[0]}; 
var d2=${comonelikes[0]}; 
var d3=${comtwolikes[0]}; 

var a=[d1,d2,d3]; 

var ticks = [${myorg},${compOne},${compTwo}]; 

plot1 = $.jqplot('chart1',[a], { 
    // Only animate if we're not using excanvas (not in IE 7 or IE 8).. 

    animate: !$.jqplot.use_excanvas, 

    seriesDefaults:{ 
     renderer:$.jqplot.BarRenderer, 
     pointLabels: { show: true }, 

    }, 
    seriesColors :[ 
        '#57c1b4','#bd66a9', 
        '#abb3b6' 
        ], 
    axes: { 
     xaxis: { 
      renderer: $.jqplot.CategoryAxisRenderer, 
      ticks:ticks, 

       tickOptions: { mark: null, 
           fontSize: 0 
          } 
     }, 
      yaxis: { 
                          min:0, 
                          max:3000000, 
      tickOptions: {formatString: '%d'}, 
      numberticks:6 
                      } 
    }, 

    highlighter: { show: true } 
}); 

$('#chart1').bind('jqplotDataClick', 
    function (ev, seriesIndex, pointIndex, data) { 
     $('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data); 
    } 
); 
}); 

これには解決策はありますか?

答えて

1

varyBarColorレンダラーオプションを使用して、色でバーをペイントするようにプロットする必要があります。

あなたseriesDefaultsにそれを追加します。ここでは

seriesDefaults:{ 
    renderer:$.jqplot.BarRenderer, 
    pointLabels: { show: true }, 
    rendererOptions: { 
     // Set varyBarColor to true to use the custom colors on the bars. 
     varyBarColor: true 
    } 
}, 

はあなたのコードと追加のバーの色とworking jsfiddle exampleです。

+0

ありがとう –

関連する問題