Jquery 弗洛特图表不会重新绘制
我在最初加载页面时得到一组数据,并将其显示在flot图表中。我有一个下拉菜单,允许用户选择“年初至今”或“月末至今”,一切正常,只是图表没有重新绘制图表,所以当您将选择更改为“月末至今”时,它仍然会在x轴上列出所有日历月,而不是一个月中的几天。我尝试过使用$.plot.setupGrid和$.plot.draw,还有chartTaggedSpending.setupGrid和chartTaggedSpending.draw,但它不起作用,所以我在这里做错了什么。提前感谢您提供的任何帮助 下面是在ajax.done函数块中调用的代码:Jquery 弗洛特图表不会重新绘制,jquery,ajax,flot,Jquery,Ajax,Flot,我在最初加载页面时得到一组数据,并将其显示在flot图表中。我有一个下拉菜单,允许用户选择“年初至今”或“月末至今”,一切正常,只是图表没有重新绘制图表,所以当您将选择更改为“月末至今”时,它仍然会在x轴上列出所有日历月,而不是一个月中的几天。我尝试过使用$.plot.setupGrid和$.plot.draw,还有chartTaggedSpending.setupGrid和chartTaggedSpending.draw,但它不起作用,所以我在这里做错了什么。提前感谢您提供的任何帮助 下面是在
if(selectView = 1 && response.length != 0) {
var chartTaggedSpending = $('#tagged-spending');
var arrMonthLabels = [[1, 'Jan'], [2, 'Feb'], [3, 'Mar'],[4, 'Apr'],
[5, 'May'],[6, 'Jun'], [7, 'Jul'], [8, 'Aug'], [9, 'Sep'], [10, 'Oct'],
[11, 'Nov'], [12, 'Dec']];
$.plot(chartTaggedSpending,
[
{
data: response[1].data,
label: 'Budgeted: ' + response[1].label,
lines: { show: true},
points: { show: true, radius: 7 }
},
{
data: response[0].data,
label: 'Spent: ' + response[0].label,
lines: { show: true},
points: { show: true, radius: 7 }
}
],
{
colors: ['#a6db34', '#33a6db'],
legend: { show: true },
grid: { borderWidth: 0, hoverable: true, clickable: true },
yaxis: {min: 0, max: 2000, ticks: 10, tickColor: '#eeeeee' },
xaxis: {
min: 1,
max: 12,
ticks: arrMonthLabels,
tickColor: '#ffffff'
}
}
);
}
if(selectView = 0 && response.length != 0) {
var chartTaggedSpending = $('#tagged-spending');
$.plot(chartTaggedSpending,
[
{
data: response[1].data,
label: 'Budgeted: ' + response[1].label,
lines: { show: true},
points: { show: true, radius: 7 },
},
{
data: response[0].data,
label: 'Spent: ' + response[0].label,
lines: { show: true},
points: { show: true, radius: 7 }
}
],
{
colors: ['#a6db34', '#33a6db'],
legend: { show: true },
grid: { borderWidth: 0, hoverable: true, clickable: true },
yaxis: {min: 0, max: 1500, ticks: 10, tickColor: '#eeeeee' },
xaxis: {
min: 1,
max: 31,
ticks: 31,
tickColor: '#ffffff'
}
}
);
}
.setupGrid和.draw是打印对象的方法。此绘图对象是从.plot调用返回的
我试图像您在这里演示的那样构造上面的代码,但我肯定遗漏了什么,因为它仍然不起作用。当我将“选择”选项更改为另一个图表时,数据会发生变化,因此我知道在此之前一切都正常,但无论我如何尝试,它都不会重新绘制图表。@hyphen,你能创建一个JSFIDLE重现你的问题吗?你能告诉我你问题的解决方案吗。其实我也有同样的问题。
var chartTaggedSpending = $('#tagged-spending');
var myPlot = $.plot(chartTaggedSpending, etc.... // assign the return from $.plot
// sometime later
myPlot.setupGrid(); // use it later
myPlot.draw();