【问题标题】:How to i set jqplot bar chart colours per bar?如何设置每个条形图的 jqplot 条形图颜色?
【发布时间】:2010-11-10 12:26:12
【问题描述】:

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

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

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

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

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

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

【问题讨论】:

    标签: colors jqplot


    【解决方案1】:

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

    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 个条形的系列,它们都是不同的灰色。

    【讨论】:

    • 这个答案并没有真正解释如何实现 TO 的要求。他的问题是关于多个系列并手动指定每个条的颜色
    【解决方案2】:

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

    你需要两件事: 设置varyBarColor和一个包含每个系列的系列颜色的系列数组,与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"]}]
                }
    

    【讨论】:

      【解决方案3】:

      这样试试

      series:[{renderer:$.jqplot.BarRenderer , seriesColors: ["#F3CBBF", "#BFDDE5", #CF3501","#eee", "#ccc", "#999"] }]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多