簡體   English   中英

沒有在條形圖柱子上獲得不同的顏色

[英]Not getting the different color on bar chart pillars

我正在使用 jqplot 編寫條形圖的代碼。 當我運行以下函數時:

問題:所有三個數據中只顯示一種顏色(第一種顏色)如何為刻度顯示不同的顏色?

$(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);
    }
);
}); 

有什么解決辦法嗎?

您需要告訴繪圖以您的顏色繪制條形,使用varyBarColor條色渲染器選項。

將它添加到您的seriesDefaults

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

這是一個帶有您的代碼和其他條形顏色的有效 jsfiddle 示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM