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

查看:230
本文介绍了如何在不重绘图表的情况下刷新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天全站免登陆