重用 jqplot 对象来加载或重新绘制数据

发布于 2024-10-09 07:18:00 字数 188 浏览 5 评论 0原文

我正在使用 JqPlot 绘制图表,我的问题是我想在不同的点击事件上加载不同的数据。

但是,一旦图表被创建并第一次加载数据;我不知道如何在另一个事件触发时加载数据,这意味着我想重用图表对象,并希望在事件触发时加载/重新绘制数据,例如...

chartObj.data = [graphData]

I am using JqPlot for charts , my problem is i want to load different data on different click events.

But once the chart is created and loaded with the data for the first time; i don't know then how to load data when another event fires that means i want to reuse the chart object and want to load/replot the data when events get fired something like...

chartObj.data = [graphData]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

泪眸﹌ 2024-10-16 07:18:00

虽然这是一个老问题了。

由于接受的答案对我不起作用,而且我也无法在 jqPlot 文档中找到解决方案。我找到了这个解决方案

var series = [[1,2],[2,3]];
chartObj.replot({data:series});

Src:查看 replot 函数。

function (am) {
    var an = am || {};
    var ap = an.data || null;
    var al = (an.clear === false) ? false : true;
    var ao = an.resetAxes || false;
    delete an.data;
    delete an.clear;
    delete an.resetAxes;
    this.target.trigger("jqplotPreReplot");
    if (al) {
        this.destroy()
    }
    if (ap || !L.isEmptyObject(an)) {
        this.reInitialize(ap, an)
    } else {
        this.quickInit()
    } if (ao) {
        this.resetAxesScale(ao, an.axes)
    }
    this.draw();
    this.target.trigger("jqplotPostReplot")
}

线路
if (ap || !L.isEmptyObject(an)) {
this.reInitialize(ap, an)
}

向我们表明 ap 需要一个真值才能将其作为第一个参数传递给内部重新初始化函数。其定义为 var ap = an.data || null;

就这么简单,但遗憾的是没有记录在我能找到的任何地方。


请注意,如果您想重绘 jqPlot 选项中定义的某些内容(例如图例标签),您可以将任何选项传递给 replot 函数。请记住要重新绘制的实际系列必须命名为“数据”

var options = {
     series : [{
            label: 'Replotted Series',
            linePattern: 'dashed'
     }],
   //^^^ The options for the plot
     data : [[1,2],[2,3]]
   //^^^ The actual series which should get reploted
}
chartObj.replot (options)

Though this is an old question.

As the accepted Answer didn't work for me and i couldn't find a solution in the jqPlot docs either. I came to this solution

var series = [[1,2],[2,3]];
chartObj.replot({data:series});

Src: Taking a look at the replot function.

function (am) {
    var an = am || {};
    var ap = an.data || null;
    var al = (an.clear === false) ? false : true;
    var ao = an.resetAxes || false;
    delete an.data;
    delete an.clear;
    delete an.resetAxes;
    this.target.trigger("jqplotPreReplot");
    if (al) {
        this.destroy()
    }
    if (ap || !L.isEmptyObject(an)) {
        this.reInitialize(ap, an)
    } else {
        this.quickInit()
    } if (ao) {
        this.resetAxesScale(ao, an.axes)
    }
    this.draw();
    this.target.trigger("jqplotPostReplot")
}

The line
if (ap || !L.isEmptyObject(an)) {
this.reInitialize(ap, an)
}

shows us it needs a truthy value for ap to pass it as first parameter to the internal reinitialize function. which is defined as var ap = an.data || null;

Its as simple as this but unfortunately not documented anywhere i could find it


Note that if you want to redraw some things defined in your jqPlot options, like legend labels, you can just pass any option to the replot function. Just remember the actual series to replot has to be named "data"

var options = {
     series : [{
            label: 'Replotted Series',
            linePattern: 'dashed'
     }],
   //^^^ The options for the plot
     data : [[1,2],[2,3]]
   //^^^ The actual series which should get reploted
}
chartObj.replot (options)
躲猫猫 2024-10-16 07:18:00

jqplot 允许快速动态数据更新。

根据文档(数据部分) ,“不应在选项对象中指定数据...” (fiddle< /a>)

plot1.replot({data: [storedData]}); // data should not be passed this way

“...但作为 $.jqplot() 函数的第二个参数传递。”

if (plot1) plot1.destroy();
plot1 = $.jqplot('chart1', [storedData]); // similar speed to replot

fiddle 表明这可以通过类似的性能来完成。

jqplot allows for a fast dynamic data update.

According to the documentation (data section), "Data should NOT be specified in the options object ..." (fiddle)

plot1.replot({data: [storedData]}); // data should not be passed this way

"... but be passed in as the second argument to the $.jqplot() function."

if (plot1) plot1.destroy();
plot1 = $.jqplot('chart1', [storedData]); // similar speed to replot

The fiddle shows this can be done with similar performance.

习惯成性 2024-10-16 07:18:00

在渲染图表之前清空图表 div

$('#graphDiv').empty();
plot = $.jqplot('graphDiv', [graphValues], graphOptions);

Empty graph div, before rendering the graph

$('#graphDiv').empty();
plot = $.jqplot('graphDiv', [graphValues], graphOptions);
故乡的云 2024-10-16 07:18:00

API 有一个 replot/redraw 方法

重绘这使得绘图数据和属性能够被更改,然后
完全清除剧情并重新绘制。

The API has a replot/redraw method

Redraw This enables plot data and properties to be changed and then to
comletely clear the plot and redraw.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文