views:

19

answers:

1

I have constructed a simple function that programatically builds charts using dojox.charting. I'm a bit puzzled as to how to cast variables correctly when passing them to the chart via addSeries. Consider this:

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

Notice that the testData variable works fine, but the convertedString variable does not. I must be missing something very simple. How would I cast an inbound string variable to work in this case?

+1  A: 
Eugene Lazutkin
Excellent! I see what I was missing now. And I agree, the variable named 'string' is painfully unimaginative. I'll make examples with better identifiers (foo!) next time. Thanks for your quick response, Eugene.
Bruce