开发者

Extjs4 chart not plotting correct data

开发者 https://www.devze.com 2023-03-14 08:51 出处:网络
I created a simple line chart in Extjs4 for one of my projects, and the chart is not plotting the right data.

I created a simple line chart in Extjs4 for one of my projects, and the chart is not plotting the right data.

Extjs4 chart not plotting correct data

The chart uses the same store as the grid, but not showing the same data. Is there any way to trace the source of the problem, if not fixing it altogether?

The following is the code I use to generate the chart.

{
    xtype: 'chart',
    animate: t开发者_JS百科rue,
    shadow: true,
    store: 'Dataalls',
    legend: {
        position: 'top'
    },
    axes: [{
        type: 'Numeric',
        position: 'left',
        title: 'Wind Speed',
        fields: ['windspeed'],
        grid: true
    }, {
        type: 'Category',
        position: 'bottom',
        title: 'Time',
        fields: ['time']
    }],
    series: [{
        type: 'line',
        axis: 'left',
        xField: ['time'],
        yField: ['windspeed']
    }]
}

(I tried using type: 'Time' for the x axis but gets the error "date.getFullYear is not a function" )


For the date.getFullYear() I suspect your date string is not parsable into a Date object. Could you post your other supporting code, ideally the full code of the Store and Grid? If you'd like to use the Time Axis you'll need to convert your date String into a date object via something along the lines of:

Ext.define('Your.Model', {
   extend: 'Ext.data.Model',
   fields: [
      {name: 'dateString', type: 'string'},
      {name: 'date',
          convert: function(value, record) {
              year = value.substring(0,4);
              month = value.substring(5,7).replace(/^[0]+/g,"");
              day = value.substring(8,10).replace(/^[0]+/g,"");
              hour = value.substring(11,13).replace(/^[0]+/g,"");
              // etc for min, sec, millis
              return new Date(year, (month - 1), day, hour, 0, 0);
          }
      }
   ]

});

For debugging the chart not displaying correctly, I'd place assign your chart object to a var and in Firebug breakpoint after that variable assignment to be able to inspect your chart js object and look at the data inside.


I had a similar problem when using Time. Just fixed it by defining my model field types:

fields: [{name: 'date', type: 'Date'}, {name: 'close',type:'float'}]

As for why your chart is plotting like that, I got that before too, I realised that the json was passing it as a string, so I need to to be defined as a float too. I did a fix for that on the php end, by forcing it as a float first before I passed it over as json.

0

精彩评论

暂无评论...
验证码 换一张
取 消