在 extjs4 中是否有更好的方法来创建具有以下数据结构的条形图?
所以我有从我的服务器返回的以下数据结构。
{date:'2/1', name: 'product 1', count: 10}
{date:'2/1', name: 'product 2', count: 5}
{date:'2/1', name: 'product 3', count: 15}
{date:'2/2', name: 'product 1', count: 11}
{date:'2/2', name: 'product 2', count: 6}
我必须运行一堆循环和字符串操作才能为堆积条形图创建以下数据结构。
{date:'2/1', product_1: 10, product_2: 5, product_3: 15 }
{date:'2/2', product_1: 11, product_2: 6, product_3: 0}
有没有更优雅的方法来解决这个问题。我对服务器端的事情没有太多控制权。
So I have the following data-structure coming back from my server.
{date:'2/1', name: 'product 1', count: 10}
{date:'2/1', name: 'product 2', count: 5}
{date:'2/1', name: 'product 3', count: 15}
{date:'2/2', name: 'product 1', count: 11}
{date:'2/2', name: 'product 2', count: 6}
I have to run through bunch of loops and string manipulation to create the following data-structure for the stacked bar chart.
{date:'2/1', product_1: 10, product_2: 5, product_3: 15 }
{date:'2/2', product_1: 11, product_2: 6, product_3: 0}
Is there a more elegant way to solve this problem. I don't have much control over the server side of things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为从一种转换为另一种的代码会相当简单。
我不认为 Ext 中有任何用于此特定转换的辅助类,并且我不认为图表系统可以接受不同的数据格式。您可以编写自己的
Model
来引用原始数据,但我认为这比上面的代码需要更多工作。I should think the code to convert from one to the other would be fairly simple.
I don't think there are any helper classes in Ext for this particular conversion, and I don't think the chart system can accept different data formats. You could write your own
Model
which references the original data, but I think that would be more work than the above code.