我有一个条形图,我需要更新它的数据,还有一个 PointLabels。数据正在更新,但 PointLabels 与之前的绘图相同。如何更新 PointLabels?
// here are labels.
var my_labels = [["2 g. <br /> 47$"],["2 g. <br /> 48$"],["7 g. <br /> 49$"],[],["10 g. <br /> 51$"],["6 g. <br /> 52$"],["4 g. <br /> 53$"]];
$.jqplot.config.enablePlugins = true;
var s1 = [2, 6, 7, '' , 10, 6, 4];
var ticks = [47,48, 49, 50, 51, 52, 53];
// initializing plot
plot1 = $.jqplot('chart1', [s1], {
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..
canvasOverlay: {
show: true,
objects: [
{verticalLine: {
name: 'barney',
x: 4,
lineWidth: 2,
color: 'gray',
shadow: false
}}
]
},
animate: !$.jqplot.use_excanvas,
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
// setting labels to my own defined labels
pointLabels: { show: true, labels : my_labels, escapeHTML: false },
color: '#E6D49F'
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks,
max: 100
}
},
highlighter: { show: false },
});
$('#chart1').bind('jqplotDataClick',
function (ev, seriesIndex, pointIndex, data) {
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
}
);
});
// reploting function call
setInterval(function(){replot()},4000);
var a = 1;
var labels;
// reploting function
function replot()
{
var data;
switch(a)
{
case 1:
data = [[1,4], [2,6], [3, 8],[4,0],[5, 9],[6, 7],[7, 3]];
labels = [["4 g. <br /> 47$"],["6 g. <br /> 48$"],["8 g. <br /> 49$"],[],["9 g. <br /> 51$"],["7 g. <br /> 52$"],["3 g. <br /> 53$"]];
break;
case 2:
data = [[1,3], [2,7], [3, 7],[4,0],[5, 8],[6, 6],[7, 4]];
labels = [["3 g. <br /> 47$"],["6 g. <br /> 48$"],["8 g. <br /> 49$"],[],["9 g. <br /> 51$"],["7 g. <br /> 52$"],["3 g. <br /> 53$"]];
break;
case 3:
data = [[1,5], [2,5], [3, 9],[4,0],[5, 10],[6, 8],[7, 2]];
labels = [["5 g. <br /> 47$"],["6 g. <br /> 48$"],["8 g. <br /> 49$"],[],["9 g. <br /> 51$"],["7 g. <br /> 52$"],["3 g. <br /> 53$"]];
break;
}
//updating data
plot1.series[0].data = data;
//trying to update pointlabels
plot1.series[0].pointLabels.labels = labels;
plot1.replot();
if(a == 3)
a = 0;
a++;
}