1

I'm a new in jqplot. Today I attempted to refresh a created line jqplot chart as the guidance from http://jsfiddle.net/fracu/HrZcj/.

First, I create a jqplot chart with a array of data, following is the code fragment:

            var colors = ['red', 'blue', 'green'];
            var dataset = [[232,234,235,556,233],[234,563,234,866,345],[234,564,567,345,234]];
            var lengeds = [{label: 'Test'}, {label: 'Upper'}, {label: 'Lower'}];
            var analysisLabels = [[1, "Label1"], [2, "Label2"], [3, "Label3"], [4, "Label4"], [5, "Label5"]];

            chart = $.jqplot("chart_id", 
                    dataset,
                    {
                        title: 'Sample Chart',
                        legend: {
                            show: true,
                            placement: 'outsideGrid'
                        },
                        series: lengeds,
                        axes: {
                           xaxis: {
                               ticks: analysisLabels,
                               tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                               tickOptions: {
                                   angle: -30
                               }
                           },
                           yaxis: {
                               label: 'Fuel',
                               labelRenderer: $.jqplot.CanvasAxisLabelRenderer
                           }
                        },
                        seriesColors: colors,
                        highlighter: { 
                            show: true 
                        },
                        cursor: {
                            show: false
                        }
                    }
                );

And then I intend to refresh it with a newly created dataset like this:

chart.series[0].data = chartSeriesTimes[0];
chart.series[1].data = chartSeriesTimes[1];
chart.series[2].data = chartSeriesTimes[2];

//chart.resetAxesScale();
chart.replot();

Chart displays nothing after the above code running, in other words, 3 formerly created curve lines are removed but newly added 3 curve dataset do not render.

I don't know why this happens since I do it follow official examples. Can anybody who good at jqplot gives me guidance. Thanks a lot.

4

3 回答 3

0

您不需要括号 [] 来放置数据集吗?

          chart = $.jqplot("chart_id", 
                [dataset],
                {
                    title: 'Sample Chart',
                    legend: {
                        show: true,
                        placement: 'outsideGrid'
                    },
                    series: lengeds,
                    axes: {
                       xaxis: {
                           ticks: analysisLabels,
                           tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                           tickOptions: {
                               angle: -30
                           }
                       },
                       yaxis: {
                           label: 'Fuel',
                           labelRenderer: $.jqplot.CanvasAxisLabelRenderer
                       }
                    },
                    seriesColors: colors,
                    highlighter: { 
                        show: true 
                    },
                    cursor: {
                        show: false
                    }
                }
于 2012-11-29T09:43:03.650 回答
0

即使我不确定这种方式是否最好,我也解决了这个问题:如果它存在,则在刷新它之前将其销毁。

if (chart) {
    chart.destroy();
}
于 2012-11-01T02:51:35.407 回答
0
if (chart) {
    chart.replot();
}
于 2015-03-12T18:57:02.930 回答