5

我想知道如何在 Jqplot 中为两个系列制作不同的颜色条。如果我只有一个系列数据,它就像下图一样完美

替代文字

红色和绿色基于其值。

但是,如果我有两个系列数据,我无法为每个系列数据配置两种系列颜色。到目前为止,我只能制作这张图

替代文字

我希望两个系列图可以根据其值以及一个系列图具有不同的颜色。

这是我的代码

chart = $.jqplot('map-chart', [dataChart, dataChart2], {
        title: 'TIME',
        legend: {
            renderer: $.jqplot.EnhancedLegendRenderer,
                        show: true,
                        location: 'ne'
        },
        series: [{label: 'Current data'}, {label: 'Worst data'}],
        //seriesColors: seriesColors1,
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            pointLabels: {show: true}
            //rendererOptions:{
             //varyBarColor: true
            //}
        },
        axes: {
            xaxis: {
                label: 'station',
                renderer: $.jqplot.CategoryAxisRenderer,
                labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
                tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                ticks: tickers,
                tickOptions: {
                    angle: -30
                }
            },
            yaxis: {
              min: 0,
              label: 'Time',
              labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
              tickOptions: {
                    fontSize: '8pt'
              }
            }
        },
        highlighter: {show: false}
    });

我试过seriesColors : [seriesColors1, seriesColors2]了,但没有用。

4

2 回答 2

9

基本上,您需要创建一个系列数组,其中每个条目包含一个字典,并带有一个seriesColors条目。以下jsfiddle中显示了一个工作示例:

plot1 = $.jqplot('chart1', [[50,100,50,50,75],[80,70,50,50,40]], 
{
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions:{ varyBarColor : true }
        },
        series: [
            {seriesColors: [ "#f00", "#4b0", "#b40", '#ff0', '#fb0']}, 
            {seriesColors: ["#a30", "#4b0", "#b40", '#af0', '#fa0']}
            ],
        highlighter: { show: false }
});

(如果我更改了外部 js 文件,小提琴可能会停止工作;jsfiddle 默认没有 jqplot 库。)

于 2011-11-21T21:10:02.230 回答
0

我今天遇到了这个问题,正如 jimbob 博士所预测的那样,所有外部文件都被链接腐烂了。我找到了一个 CDN 站点并将小提琴更新为最新的 jQuery 和 JQPlot 资源文件,可在此处获得:http: //jsfiddle.net/delliottg/WLbGt/96/

只是为了满足关于 SO 的 JSFiddle 警察不会让我在没有它的情况下发布这个:

//this is not my code, it's only here to satisfy the SO require that fiddles have
// code associated with them
plot1 = $.jqplot('chart1', [[50,100,50,50,75],[80,70,50,50,40]], {
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            rendererOptions:{ varyBarColor : true }
        },
    series: [
            {seriesColors: [ "#f00", "#4b0", "#b40", '#ff0', '#fb0']}, 
            {seriesColors: ["#00f",  "#b0b", "#a30", "#4b0", '#af0']}
            ],
        highlighter: { show: false }
});

我与小提琴本身无关,我只是更新了它,所以它可以工作。希望这对某人有所帮助(事实证明这不是我想要的,但你付了钱,你抓住了机会)。

于 2014-11-05T23:34:12.177 回答