如何在不重绘图表的情况下刷新 jqplot 条形图 [英] How to refresh jqplot bar chart without redrawing the chart

查看:17
本文介绍了如何在不重绘图表的情况下刷新 jqplot 条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 jqplot 条形图,我希望在用户更改下拉列表中的值时更改图表数据.这行得通,但问题是每次用户更改值时,条形图都会一个接一个地重绘.

I have a jqplot bar chart and I want the chart data to be changed when the user changes the value on a drop-down list. That works, but the problem is the bar chart redraws, one over another, each time the user changes the values.

如何在不重新绘制整个内容的情况下更新或重新加载条形图?有没有要设置的属性值?

How can I update or reload the bars without drawing the whole thing again? Is there any property value to be set?

图表数据根据 ajax 调用发生变化:

Chart data changes according to an ajax call:

$.ajax({
    url: '/Home/ChartData',
    type: 'GET',
    data: { Id: Id },
    dataType: 'json',
    success: function (data) {
        $.jqplot('chartDiv', [a, b], CreateBarChartOptions(xAxis));
}});

function CreateBarChartOptions(xAxis) {
    var optionsObj = {
        title: 'Stat',
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: xAxis
            },
            yaxis: { min: 0 }
        },
        series: [{ label: 'A' }, { label: 'B'}],

        seriesDefaults: {
            shadow: true,
            renderer: $.jqplot.BarRenderer,
            rendererOptions: {
                barPadding: 8,
                barMargin: 10
            }
        },

    };
    return optionsObj;
}

我们将不胜感激.谢谢.

A reply would be highly appreciated. Thanks.

推荐答案

你要做的是在绘制新图表时调用 jqPlot 的 .replot() 方法.将您的 ajax 调用更改为如下所示:

What you want to do is call jqPlot's .replot() method when you draw the new chart. Change your ajax call to look like this:

$.ajax({
        url: '/Home/ChartData',
        type: 'GET',
        data: { Id: Id },
        dataType: 'json',
        success: function (data) {

            $.jqplot('chartDiv', [a, b], CreateBarChartOptions(xAxis)).replot();
        }});

这篇关于如何在不重绘图表的情况下刷新 jqplot 条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆