c# - 图表不会得出我的观点

标签 c# javascript asp.net ajax flot

enter image description here

我的问题出在这张图片上。我正在尝试绘制一个以传感器数据作为我的点 (X,y) 的图表。当网页加载时,它会读取一个 csv 文件并将此数据发送到来 self 的代码隐藏的 ajax 调用。这是我背后的代码返回的内容:

var myData = new Stats { 
                Time = dataContainer.time,
                LhXVals = dataContainer.lhXVals,
                LhYVals = dataContainer.lhYVals,
                LhZVals = dataContainer.lhZVals,
                RhXVals = dataContainer.rhXVals,
                RhYVals = dataContainer.rhYVals
            };

这是我的 Stats 类的样子。我解析数据然后将其存储在列表中。 enter image description here

然后我将其发送到 ajax 调用。这是我的 ajax 成功函数:

        var time = new Array();
        var lhXVals = new Array();
        var cumulative = new Array();
        var data2;

success: function (result) {
                        time = result.d.Time; //Time is a List<double>
                        lhXVals = result.d.LhXVals; //Left-Hand-X-Values is a List<double>, both are the same size

                        //check if time and lhXVals are empty, if not proceed
                        if (time.length > 0 || lhXVals.legnth > 0) {
                            for (var i = 0; i < time.length; ++i) {
                                //only grabbing little bit of data just to test, 
                                //only taking first 2 elements
                                if (i == 6)
                                    break;
                                //use the time data ex:(510.2838439) as my X-axes
                                //use the left-hand-X-Values ex:(23.9384384) as my Y-axes
                                debugger;
                                cumulative.push([parseFloat(time[i]), parseFloat(lhXVals[i])]);//data2 was a manually populated example i used before
                                data2 = [[4.53123342, 0], [4.9039293, 24.89323233], [6, 0], [6, -12.134], [8, 0], [8, 6.932]];

                                //an index in the "cumulative" array would look like this:
                                // [0]: [510.2838439,23.9384384]
                            }
                        }
                        updateOnce(cumulative);

updateOnce(cumulative); 函数接受我在 flot.setData() 方法中使用的累积点数组来绘制新图形。

function updateOnce(cumulative) {
                debugger;
                plot.setData([cumulative]);
                plot.draw();//draws nothing
            }

然而,最大的问题是,当 plot.draw(); 被绘制时,我的图表上什么也没有,我也不知道为什么。我已经尝试了我能想到的一切。我试过将数据解析为 float ,然后保留它但没有改变任何东西。我在“累积”中的数据存储与我为图形点创建的手动数组(var 数据)完全相同,但它不起作用,我一直在努力。

编辑 对于下面的评论。我最初是这样设置的:

function updateOnce(cumulative) {
                debugger;
                plot.setData([cumulative]);
                plot.draw(); //draws nothing
            }

            //implementing getData Last
            var plot = $.plot("#placeholder", [getData()], {
                series: {
                    shadowSize: 0   // Drawing is faster without shadows
                },
                yaxis: {
                    min: -50,
                    max: 50
                },
                xaxis: {
                    show: true
                }
            });

我返回的数据是手动设置的点 (x,y) 数组,因此它会首先在图形上绘制一些东西,它确实这样做了。然后当 ajax 最终返回一些数据时,我用返回的数据启动重绘。

最佳答案

如果坐标轴的最小值/最大值在 setData 调用中发生变化,您需要调用 plot.setupGrid() 来重新计算坐标轴。来自documentation , 加粗我的:

setData(data)

You can use this to reset the data used. Note that axis scaling, ticks, legend etc. will not be recomputed (use setupGrid() to do that). You'll probably want to call draw() afterwards.

You can use this function to speed up redrawing a small plot if you know that the axes won't change. Put in the new data with setData(newdata), call draw(), and you're good to go. Note that for large datasets, almost all the time is consumed in draw() plotting the data so in this case don't bother.

setupGrid()

Recalculate and set axis scaling, ticks, legend etc.

Note that because of the drawing model of the canvas, this function will immediately redraw (actually reinsert in the DOM) the labels and the legend, but not the actual tick lines because they're drawn on the canvas. You need to call draw() to get the canvas redrawn.

关于c# - 图表不会得出我的观点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20939346/

相关文章:

c# - B-Trees/B+Trees 和重复键

c# winforms - 在模式窗体之间传递参数

javascript - 粒子 slider Logo 不会在 Safari 中调整大小

javascript - JS 函数通过生成的值用唯一元素填充数组

c# - AcceptSocket 不尊重 Thread.Abort 请求

c# - 数据表:数据表结果中的 System.Byte[] 值

javascript - 使图像可旋转 jquery UI

asp.net - 网站部署后需要强制刷新

c# - Entity Framework 6从存储过程获取复杂的返回值

asp.net - iOS 和 ADFS 保护的网站