Dojo DataChart 和手动 ItemFileWriteStore 更新
我决定尝试一下 Dojo,而不是使用 JQuery,但在操作数据存储时遇到了麻烦。我有一个 DataChart,它绑定到我从 Web 套接字 JSON 消息手动填充的 ItemFileWriteStore 的内容:
fakeData = {
"identifier": "name",
"label": "Some data i'd like to add to later",
"items": [
{
"name": "appendToMe",
"values": [0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 0.0]
}
]
};
store = new dojo.data.ItemFileWriteStore({
data: fakeData
});
var chart = new dojox.charting.DataChart("chartDiv", {});
chart.setStore(store, {"name":"*"}, "values");
此时,该图正在显示我创建的“appendToMe”系列。接下来,我收到另一条消息,其中包含“appendToMe”值列表的一些新数值。 如何将其添加到商店,这是否足以触发图表更新?
我查看了 [](write API) 'store.setValue',但看起来我只能使用它来将整个值块替换为一个单元。此外,我没有可用于调用的“item”句柄,该句柄似乎仅在您使用 newItem
API 而不是使用 JSON 构建存储时才可用。
干杯!
斯科特
I've decided to give Dojo a shot instead of using JQuery for once, and am having trouble manipulating a data store. I've got a DataChart bound to the contents of an ItemFileWriteStore i've populated by hand from a web socket JSON message:
fakeData = {
"identifier": "name",
"label": "Some data i'd like to add to later",
"items": [
{
"name": "appendToMe",
"values": [0.0, 1.0, 2.0, 3.0, 2.0, 1.0, 0.0]
}
]
};
store = new dojo.data.ItemFileWriteStore({
data: fakeData
});
var chart = new dojox.charting.DataChart("chartDiv", {});
chart.setStore(store, {"name":"*"}, "values");
At this point, the graph is displaying the "appendToMe" series i've created. Next, I receive another message, containing some new numeric value for the "appendToMe" values list.
How do I add it to the store, and will this be sufficient to trigger the graph to update?
I've looked at the [](write API) 'store.setValue', but it looks like I can only use this to replace the whole values chunk as one unit. In addition, I don't have a 'item' handle to use with the call, which appears to only be available if you use the newItem
API instead of constructing the store with JSON.
Cheers!
Scott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要获取appendToMe 项目。
然后在 onItem 中,获取值,修改它们,然后使用 store.setValue() 再次设置它们。
如上所述,需要使用 getValues 来返回值数组,而不是通常的 getValue,后者从不返回数组。与 setValues 类似。
http://dojotoolkit.org/api/1.6/dojo/data/api/Read
setValues()
http://dojotoolkit.org/api/1.6/dojo/data/api/Write
First you need to fetch the appendToMe item.
Then in the onItem, get your values, modify them, and then set them again using store.setValue()
As noted, getValues needs to be used to return the array of values instead of the usual getValue, which never returns an array. And similar with setValues.
http://dojotoolkit.org/api/1.6/dojo/data/api/Read
setValues()
http://dojotoolkit.org/api/1.6/dojo/data/api/Write