0

我已将正面和负面数据合并到一个名为 yAxis 的数据集(正面和负面的多列)。这是代码:

//...

var yAxis = [wololoTotalValues];
var xAxis = wololoTotalKeys;

window.onload = function () {
    Flotr.draw(document.getElementById("chart"), yAxis, {
        title: "wololo",
        bars: {
            show: true,
            barWidth: 0.8
        },
        yaxis: {
            min: 0,
            max: wololoMaxValue + 10,
            tickDecimals: 0
        },
        xaxis: {
            ticks: xAxis
        }
    });
};  

//...
<div id='chart' style="width:1200px;height:500px;"></div>

这是现在的样子

我希望'bad'和'ble'是红色的。我找到了一些手册如何用 flot 处理这个问题,但不是 flotr(flotr2)。

有没有办法让它像下面这样?或者也许我必须像这里一样拆分数据?

colors: (yAxis[0-lastGood] : "#0000FF"), (yAxis[lastGood+1-lastBad] : "#FF0000")
4

1 回答 1

0

好的,找到了解决方案,将数据分成两个数组有帮助。代码如下:

            var gud = [];
            for(i=0; i<wololoLengthGood; i++){
                gud.push([i, wololoValuesGood[i]]);
            }

            var bad = [];
            for(i=wololoLengthGood; i<wololoLengthGood+wololoLengthBad; i++){
                bad.push([i, wololoValuesBad[i-wololoLengthGood]]);
            }

            window.onload = function () {
                Flotr.draw(document.getElementById("chart"), 
                [{                         // replacement of 'yAxis' from here
                    data: gud,
                    color: "#0000FF"
                },{
                    data: bad,
                    color: "#FF0000"
                }],                        // till here.
                //...
于 2015-08-10T08:02:07.127 回答