13

我正在尝试设置我的 jqplot 条形图条的颜色。将始终存在六个条形图,分为 2 个条形图。以下是绘制数据的示例:

 line1 = [6000, 5000, 5500];
 line2 = [16000, 10000, 14000];

到目前为止,我已经使用了以下内容:

 seriesColors: ["#F3CBBF", "#BFDDE5", "#CF3501", "#027997", "#CF3501", "#027997"],

但是 jqplot 每次在前 2 个条之间交替,而不是使用所有声明的颜色。这可能是因为它只确定存在 2 个系列,每组数据一个。

有没有办法明确设置条形颜色?

4

3 回答 3

31

我使用varyBarColor 方法来执行此操作,因此您可以像已经完成的那样在一个简单的数组中列出条形的不同颜色,但是如果只有一个系列,它将为每个条形使用这些颜色。这是我的代码示例:

plot1 = $.jqplot('chart1', [s1], {
        title: 'Example Income Graph',
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions:{ varyBarColor : true },
            pointLabels: { show : true }
        },
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                label:'Net Growth (%)',
                ticks: ticks
            },
            yaxis:{
              label:'Income (£)',
              tickOptions:{ formatString:'%d'},
              autoscale:true,
              min:0, 
              max:10000
            }
        },
        seriesColors: [ "#eee", "#ccc", "#999"],
        highlighter: { show: false }
    });

在这张图中,我有一个包含 3 个条形的系列,它们都是不同的灰色。

于 2011-01-02T12:18:10.833 回答
4

这已经很老了,但仍然没有正确的答案,我花了一段时间才弄清楚,所以就这样吧。

你需要做两件事:设置变量BarColor和一个包含每个系列的系列颜色的系列数组,与seriesDefaults在同一级别传递,例如:

plot1 = $.jqplot('chart1', [s1, s2], {
            title: 'Example',
            seriesDefaults:{
                renderer:$.jqplot.BarRenderer,
                rendererOptions:{ varyBarColor : true },
                pointLabels: { show : true }
            },
            series: [{seriesColors: ["#F3CBBF", "#BFDDE5", "#CF3501"]},
                     {seriesColors: ["#027997", "#CF3501", "#027997"]}]
            }
于 2014-04-17T18:01:48.723 回答
-1

试试这样

series:[{renderer:$.jqplot.BarRenderer , seriesColors: ["#F3CBBF", "#BFDDE5", #CF3501","#eee", "#ccc", "#999"] }]
于 2014-05-27T12:54:48.470 回答