2014-01-14 34 views
0

我正在使用Dojo 1.9,使用memoryStore並且存儲除了密鑰外還有4個數據元素。對於4個數據元素中的每一個,我需要繪製一個餅圖。工作正常,但唯一的問題是,我不知道如何指定顏色。在Dojo圖表中指定餅圖的顏色

標識符可以是以下之一 - 低,中,高和極端。 我想爲每個標識符在所有圖表中使用相同的顏色。我能否根據標識符的值指定顏色?

的代碼片段如下圖所示:

var store = new Observable(new Memory({ 
    data: { 
    identifier: "accumulation", 
    items: theData 
    } 

    })); 


    theChart.setTheme(PrimaryColors) 
    .addPlot("default", { 
    type: Pie, 
    font: "normal normal 11pt Tahoma", 
    fontColor: "black", 
    labelOffset: -30, 
    radius: 80 
    }).addSeries("accumulation", new StoreSeries(store, { query: { } }, dataElement)); 

回答

1

我可能誤解了你的問題在這裏(?是小區直接與店內交互StoreSeries),反而是fill屬性你正在找?

// Assuming data is an array of rows retrieved from the store 
for(var i etc...) { 
    // make chart 
    // ... 
    chart.addSeries("things", [ 
     { y: data[i]["low"], fill: "#55FF55", text: "Low" }, 
     { y: data[i]["mod"], fill: "#FFFF00", text: "Moderate" }, 
     { y: data[i]["high"], fill: "#FFAA00", text: "High" }, 
     { y: data[i]["extr"], fill: "#FF2200", text: "Extreme" } 
    ]); 
} 

更新:當使用StoreSeries,(在你的代碼dataElement)的第三個參數也可以是一個函數。您可以使用該函數返回一個對象(包含上述屬性,例如fill)而不僅僅是一個值。

chart.addSeries("thingsFromStore", new StoreSeries(store, {}, function(i) { 
    return { 
     y : i[dataElement], 
     text: "Label for " + i.accumulation, 
     fill: getColorForAccumulation(i) 
    };  
})); 
+0

我已經用代碼片段更新了問題 – patb23

+0

是的,但不知道如何在使用存儲時定義它。 – patb23

+0

@ patb23嗯,第二次嘗試在更新的答案:) – Frode