2014-01-14 37 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