Javascript 为什么在控制台中显示错误:“;“未指定数据”;使用jqPlot后
假设x轴和y轴分别有两个数组。我正在尝试用jsPlot绘制折线图。我已经这样做了:Javascript 为什么在控制台中显示错误:“;“未指定数据”;使用jqPlot后,javascript,jquery,jqplot,Javascript,Jquery,Jqplot,假设x轴和y轴分别有两个数组。我正在尝试用jsPlot绘制折线图。我已经这样做了: if (watervalue.length != 0) { for (var a = 0; a < watervalue.length; a++) { wvalues += '[' + months[watermonth[a]] + ',' + watervalue[a] + '],';
if (watervalue.length != 0) {
for (var a = 0; a < watervalue.length; a++) {
wvalues += '[' + months[watermonth[a]] + ',' + watervalue[a] + '],';
}
}
wvalues = wvalues.slice(0, -1) + ']';
var plot2 = $.jqplot('container1', wvalues, {
// Give the plot a title.
title: 'Plot With Options',
// You can specify options for all axes on the plot at once with
// the axesDefaults object. Here, we're using a canvas renderer
// to draw the axis label which allows rotated text.
axesDefaults: {
labelRenderer: $.jqplot.CanvasAxisLabelRenderer
},
// Likewise, seriesDefaults specifies default options for all
// series in a plot. Options specified in seriesDefaults or
// axesDefaults can be overridden by individual series or
// axes options.
// Here we turn on smoothing for the line.
seriesDefaults: {
rendererOptions: {
smooth: true
}
},
// An axes object holds options for all axes.
// Allowable axes are xaxis, x2axis, yaxis, y2axis, y3axis, ...
// Up to 9 y axes are supported.
axes: {
// options for each axis are specified in seperate option objects.
xaxis: {
label: "X Axis",
// Turn off "padding". This will allow data point to lie on the
// edges of the grid. Default padding is 1.2 and will keep all
// points inside the bounds of the grid.
pad: 0
},
yaxis: {
label: "Y Axis"
}
}
});
if(watervalue.length!=0){
对于(var a=0;a
它显示错误,未指定数据
wvalues
的console.log
输出为:
[[二月零日],[三月零日],[四月零日],[五月零日],[六月零日],[七月七日]]
哪里出了问题?你必须这么做。修改for循环,如下所示,并删除wvalues=wvalues.slice(0,-1)+']代码>行
var-months=[“二月”、“三月”、“四月”、“五月”、“六月”、“七月”];
var-watervalue=[0,0,0,0,0,7];
var wvalues=[];
var tmp=[];
对于(var i=0;i //输出:[“二月”,0],“三月”,0],“四月”,0],“五月”,0],“六月”,0],“七月”,7]
我不熟悉“jsPlot”,但是你不应该传递一个数组
对象而不是字符串
?