1

I've created an array (myData) from a for loop and stored it in a variable, however I'm unable to plot the data via highcharts.

I've added an array (arr) containing numbers (i.e not via the for loop) to test and it works when using this array.

Example in http://jsfiddle.net/o22uk7Lb/

HTML

myData<p id="demo"></p>
arr<p id="demo2"></p>

<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>

Javascript

var mp = 300;
var yp = (mp * 12);
var year = new Array(12);
var myData = [];
for (var i = 1; i <= year.length; i++){
    myData +=  (i * yp.toFixed(2)) + ",";
};
document.getElementById("demo").innerHTML = myData; 

 var arr = [100,200,300,400,500];
 document.getElementById("demo2").innerHTML = arr; 
 Highcharts.chart('container', {
    chart: {
        type: 'column'
    },

    plotOptions: {
        bar: {
            dataLabels: {
                enabled: true
            }
        }
    },
    series: [{
        data: myData
    },]
 })

1 Answer 1

1

Your for loop is not populating an array, it's creating a string.

Try this:

for (var i = 1; i <= year.length; i++){
    myData.push(i * yp.toFixed(2));
};

Updated fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.