使用指定的 x 和 y 值更新动态 Dojo 图表
我正在建立一个网站,需要动态更新折线图。 为此,我使用 dojo 库,它提供了实现此目的所需的必要图表函数,完全基于其网站上提供的此示例:
http://dojotoolkit.org/documentation/tutorials/1.6/charting_advanced/
http://dojotoolkit.org/documentation/tutorials/1.6/charting_advanced/demo/store-series.html
此示例向我展示了如何使用新的 y 值更新图表并递增该值x 减一。 我需要的是使用自定义值 (x,y) 更新图表并绘制它,但我找不到方法来执行此操作。 我尝试直接在数据存储中强制输入 x 和 y 的值,但没有结果,图表也无法加载:
// Initial data
var data = [
// This information, presumably, would come from a database or web service
{ id: 1, x:0, y:20, site: 1 },
{ id: 2, value: 16, site: 1 },
{ id: 3, value: 11, site: 1 },
{ id: 4, value: 18, site: 1 },
{ id: 5, value: 26, site: 1 },
{ id: 6, value: 19, site: 2 },
{ id: 7, value: 20, site: 2 },
{ id: 8, value: 28, site: 2 },
{ id: 9, value: 12, site: 2 },
{ id: 10, value: 4, site: 2 }
];
// Create the data store
// Store information in a data store on the client side
var store = dojo.store.Observable(new dojo.store.Memory({
data: {
identifier: "id",
label: "Users Online",
items: data
}
}));
Google 没有为我提供更多帮助。 如何使用自定义 (x,y) 值对动态更新此数据存储? 还有其他方法可以做到这一点吗?
此致
I'm building a website which requires a line graph to be updated dynamically.
For this I'm using the dojo library which provides the necessary charting functions I need to achieve this, based fully on this example available on their website:
http://dojotoolkit.org/documentation/tutorials/1.6/charting_advanced/
http://dojotoolkit.org/documentation/tutorials/1.6/charting_advanced/demo/store-series.html
This example show me how to update the graph with a new value of y and increments the value of x by one.
What I need is to update the chart with a custom value of (x,y) and plot it but I cant't find a way to do this.
I tried forcing the values of x and y directly on the data store but with no results, the chart won't load:
// Initial data
var data = [
// This information, presumably, would come from a database or web service
{ id: 1, x:0, y:20, site: 1 },
{ id: 2, value: 16, site: 1 },
{ id: 3, value: 11, site: 1 },
{ id: 4, value: 18, site: 1 },
{ id: 5, value: 26, site: 1 },
{ id: 6, value: 19, site: 2 },
{ id: 7, value: 20, site: 2 },
{ id: 8, value: 28, site: 2 },
{ id: 9, value: 12, site: 2 },
{ id: 10, value: 4, site: 2 }
];
// Create the data store
// Store information in a data store on the client side
var store = dojo.store.Observable(new dojo.store.Memory({
data: {
identifier: "id",
label: "Users Online",
items: data
}
}));
Google didn't help me much more.
How can I dynamically update this data store with a custom (x,y) value pair?
Is there any other way to do this?
Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用文本输入更改了一些 (x,y) 值。解决方案非常简单(如果我理解你的问题):
希望有帮助!
Let's say that you change some of the (x,y) values using an text input. The solution quite simple (if I understood your question):
Hope it helps!
好吧,这会有点长,我知道我迟到了 7 年,但这是我用于创建动态更新图表的代码。
在 html 中,我有两个带有 id 的按钮,如按钮元素中所述,以及一个用于实现图表的图表节点。如果有人需要的话,我也可以放置我的 dojoConfig,但我从教程中获得了它,所以那里没有隐藏任何大知识。
Ok this is going to be a bit long and i know i am 7 years late, but here is my code for creating a dynamically updating chart.
and in html i have two buttons with id's as explained in the button elements, as well as a chartNode to implement the chart. I can also put my dojoConfig if someone needs it but i got from the tutorials so no big knowledge hidden there.