我构建了一个简单的函数,它使用 dojox.charting 以编程方式构建图表。我对通过 addSeries 将变量传递到图表时如何正确转换变量感到有些困惑。考虑一下:
function buildChart(targetDiv){
//grab the destination
var bc = dojo.byId(targetDiv);
//define the data for the series
var testData = [2,4,2,2,2,3,2,10,11,12,8,4];
var string = "2,4,2,2,2,3,2,10,11,12,8,4";
var convertedString = string.split(",");
console.log("Variable testData value is " + typeof(testData));
console.log("Variable convertedString value is " + typeof(convertedString));
//build the chart
dojo.attr(bc,"style","width:300px;height:200px;");
var chart = new dojox.charting.Chart2D(bc);
chart.addPlot("default", {type: "Lines"});
chart.addAxis("x");
chart.addAxis("y", {vertical: true});
//chart.addSeries("Series 1 works fine", testData);
chart.addSeries("Series 2 not working", convertedString);
chart.render();
}//buildChartenter code here
请注意,testData 变量可以正常工作,但 convertString 变量不能。我一定错过了一些非常简单的东西。在这种情况下,我将如何转换入站字符串变量?