Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
731 views
in Technique[技术] by (71.8m points)

jquery plugins - How to refresh jqplot bar chart without redrawing the chart

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
        }});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...