简体   繁体   English

EXT JS 4折线图显示数据不正确

[英]EXT JS 4 Line Chart Displays Data Incorrectly

My problem is extremely similar to the one described in this SO question , but not quite the same. 我的问题与该SO问题中描述的问题极为相似,但并不完全相同。

I'm dynamically populating a chart from the database with a timestamp and a integer value that should display on a line chart. 我正在使用时间戳和应在折线图上显示的整数值从数据库中动态填充图表。 The chart displays the data incorrectly. 图表显示数据不正确。 For instance, this data set has 3 items with y = 1, y = 5, y = 1 matched with the corresponding X value timestamps below. 例如,此数据集包含3个项,其中y = 1,y = 5,y = 1与下面相应的X值时间戳匹配。 外部图表问题

This chart has two items with y=1 and y =1 at the timestamps indicated on the X axis. 该图表在X轴指示的时间戳上有y = 1和y = 1的两项。 Problem is, the chart duplicated itself twice here. 问题是,图表在此处重复了两次。 Not sure what's going on. 不知道发生了什么。 EXT时髦的Y轴

As you can see, the highlighted element indicates the point should graph at y = 5, not y = 1.5ish. 如您所见,突出显示的元素指示该点应在y = 5处绘制,而不是y = 1.5ish。 The far left point should also start at y = 1, not y = 0. I've been reading documentation, forums, and SO all day and am quite flummoxed. 最左边的点也应该从y = 1开始,而不是y =0。我整天都在阅读文档,论坛和SO,并且非常困惑。 I've even rewritten the silly thing twice now to follow "good" examples and that doesn't seem to help either. 我现在已经按照“好的”例子重写了两次傻事,但这似乎也无济于事。

The model code, 型号代码,

  Ext.define('ROOT.model.dataset', {
    extend: 'Ext.data.Model',
    alias: 'event',
    fields: ['count', 'time'],

    constructor: function (config) {
        this.callParent(arguments);
        Ext.apply(this, config);
    }
});

The graph code, 图形代码

Ext.define('Root.view.ChartPanel', {
    extend: 'Ext.panel.Panel',
    title: 'Event Metrics',

    initComponent: function () {
        Ext.apply(this, {
            store: new Ext.data.SimpleStore({fields: [
            {name: 'count', type: 'int'},
            {name: 'time', type: 'string'}
            ]})
        });
        this.callParent(arguments);

        //CREATE CHART
        this.barChart = Ext.create('Ext.chart.Chart', {
            renderTo: Ext.getBody(),
            width: 700,
            height: 500,
            animate: false,
            store: this.store,

            axes: [
                {
                    type: 'Numeric',
                    position: 'left',
                    fields: ['count'],
                    label: {
                        renderer: Ext.util.Format.numberRenderer('0,0')
                    },
                    title: 'Count',
                    grid: true,
                    adjustMaximumByMajorUnit: false,
                   adjustMinimumByMajorUnit: false,
                    minorTickSteps: 5,
                    majorTickSteps: 3,
                    minimum: 0
                },
                {
                    type: 'Category',
                    position: 'bottom',
                    fields: ['time'],
                    title: 'Date'
                }
            ],

            series: [
                {
                    type: 'line',
                    axis: ['left', 'bottom'],
                    highlight: true,
                    tips: {
                        trackMouse: true,
                        width: 175,
                        height: 20,
                        renderer: function(storeItem, item) {
                            this.setTitle(storeItem.get('time') + ': ' + storeItem.get('count'));
                        }
                    },
                  /*  label: {
                        display: 'insideEnd',
                        field: 'count',
                        renderer: Ext.util.Format.numberRenderer('0'),
                        orientation: 'horizontal',
                        color: '#333',
                        'text-anchor': 'middle',
                        constrast: true
                    },*/
                    xField: 'time',
                    yField: ['count'],
                    markerConfig: {
                        type: 'cross',
                        size: 4,
                        radius: 4,
                        'stroke-width': 0
                    }
                }   
            ]
        });
        this.add(this.barChart);
    }, //end init



    refreshEventChart: function (data) {
        this.clear();
        this.store.loadData(data);
        this.barChart.redraw();
    },

    clear: function() {
        this.store.removeAll();
        this.barChart.surface.removeAll();
    }
});

Any help figuring this out would be greatly appreciated! 任何帮助弄清楚这一点将不胜感激!

I've discovered the problem. 我发现了问题。 It turns out my data provider wasn't converting a value from a string to an integer when I requested the data--hence the seemingly wonky chart. 事实证明,当我请求数据时,我的数据提供者并没有将值从字符串转换为整数,因此看似摇摇欲坠的图表。 After modifying the data provider to ensure the count field always produces an integer, when coming from the server, the charts started working fine. 修改数据提供程序以确保count字段始终生成整数之后,图表从服务器发出时可以正常工作。

I had the same problem and after applying your solution to my php code with JSON_NUMERIC_CHECK 我遇到了同样的问题,并且在使用JSON_NUMERIC_CHECK将您的解决方案应用于我的PHP代码之后

json_encode($response, JSON_NUMERIC_CHECK );

the problem still wasn't resolved. 问题仍然没有解决。

I am dynamically generating my line graph and have to input the maximum step value when I do. 我正在动态生成线形图,因此必须输入最大步长值。 I discovered that If the maximum is set less than 5 the step will break, if the value is 5 or greater the step looks just fine. 我发现如果将最大值设置为小于5,则该步骤将中断,如果该值是5或更大,则该步骤看起来很好。

  axes: [{
            type: 'Numeric',
            minimum: 0,                
            maximum: maxValue,                     
            position: 'left',
            fields:  vs ,
            grid: true,
            title: 'Visitors',
            label: {
               renderer: Ext.util.Format.numberRenderer('0,0'),
                font: '10px Arial'
            }

hope this helps someone else. 希望这对其他人有帮助。
Link to image of example where maxValue is set to 4 and 5 http://swimmingturtle.com/temp/lt5_max.png 链接到示例示例,其中maxValue设置为4和5 http://swimmingturtle.com/temp/lt5_max.png

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

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