简体   繁体   English

ExtJS:在网格和图表之间共享存储

[英]ExtJS: share store between grid and chart

I'm writing a simple application storing and displaying timestamped messages. 我正在编写一个简单的应用程序,用于存储和显示带有时间戳的消息。 Messages are JSON objects containing, say 2 main fields like: 消息是JSON对象,其中包含2个主要字段,例如:

{
  "emitted": "2011-12-08 12:00:00",
  "message": "This is message #666"
}

I have a model to describe these messages: 我有一个模型来描述这些消息:

Ext.define('Message', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'emitted', type: 'date'   },
        { name: 'message', type: 'string' }
    ]
});

I have no problem displaying these messages in a grid. 我在网格中显示这些消息没有问题。 However, i would now like to display these messages in a chart. 但是,我现在想在图表中显示这些消息。 For instance, I would be able to grab numbers (like the #666 in the above example) and display a line chart. 例如,我将能够获取数字(如上述示例中的#666)并显示折线图。

Ideally, i don't want to create a new store for the chart, i would like to reuse the same message store, but apply a filter on the fields to grab the proper value. 理想情况下,我不想为图表创建新的存储,我想重复使用相同的消息存储,而是在字段上应用过滤器以获取适当的值。 I don't know, something that might look like: 我不知道,可能看起来像这样:

var chart = {
    xtype:   'chart',
    ...
    series: [{
        type:   'line',
        axis:   ['left', 'bottom'],
        xField: 'emitted',
        yField: {fieldName:'message', fieldGrabber: function(v) {
            new RegExp("This is message #(\d+)$", "g").exec(v)[1]
        }}
    }]
};

Does this kind of thing is possible in ExtJS ? 在ExtJS中这种事情可能吗? I just tried to explain what I'm trying to do, i have no idea where to find such a feature: in the chart class, in the store class, or using a kind pf proxy to the store. 我只是试图解释我要做什么,我不知道在哪里可以找到这样的功能:在图表类中,在商店类中,还是对商店使用一种pf代理。

Side note: I cannot ask the data to be properly formatted to the server. 旁注:我不能要求将数据正确格式化到服务器。 The messages I receive are not backed up anywhere, they are just live events streamed to the client via socketIO. 我收到的消息不会在任何地方备份,它们只是通过socketIO流传输到客户端的实时事件。

Any advices greatly appreciated! 任何建议,不胜感激!

You should extract the value inside you model to a separate field: 您应该将模型内部的值提取到单独的字段中:

Ext.define('Message', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'emitted', type: 'date'   },
        { name: 'message', type: 'string' },
        { name: 'nr', convert: function(v, r){
            return r.get('message').replace(/^.*#/, '');
        } }
    ]
});

Or you might be better off just having the 'nr' field and using a renderer in Grid that displays it as "This is message #{nr}". 或者,最好只具有'nr'字段并在Grid中使用将其显示为“ This is message#{nr}”的渲染器。

Then you can use the 'nr' field directly in you chart. 然后,您可以直接在图表中使用“ nr”字段。

我切换到Highcharts并将ExtJS扔到垃圾箱:P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM