0

I have a fuction to make my string array and pass this value to data inside highchart.

(function ($, window, myapp) {
    $(document).ready(function () {

        console.log('the data array', myApp.dataArray);
        var conteudo = [];
        for (var i = 0; i < myApp.dataArray.length; i++) {

            conteudo += "[\""
            conteudo += myApp.dataArray[i][0];
            conteudo += "\",";
            conteudo += myApp.dataArray[i][1];

            if (i == myApp.dataArray.length-1) {
                conteudo += "]";
            } else {
                conteudo += "],";
            }

        }


        console.log(conteudo);
        chart(conteudo);

    });
})(jQuery, window, myApp);

The result console.log is correct on variable conteudo ["2017-11-21",600000],["2017-11-22",-1200000],["2017-11-23",300000]

The problem is pass conteudo variable to hightchart:

        series: [{
            name: 'Hours',
            colorByPoint: true,
           
                    data: [
                    
                   conteudo

                ]
            
        }]

1
  • I tried it, doesnt work. Commented Nov 28, 2017 at 11:53

1 Answer 1

1

I think you should pass array object to data field. No need to convert to string.

Also

["2017-11-21",600000],["2017-11-22",-1200000],["2017-11-23",300000]

This is not string array.

As I understand you are trying to do something like this:

data: [{
  name: '2017-11-21',
  y: 600000
}, {
  name: '2017-11-22',
  y: -1200000
}]

You can check an example http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/series/data-array-of-objects/

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

4 Comments

No, It´s diferent.I need pass exactly ["2017-11-21",600000],["2017-11-22",-1200000],["2017-11-23",300000] if I put manually my grafh works perfectly
@lorranpalmeira What about this solution? jsfiddle.net/a0k3Lxbz Just use an array instead of a string
conteudo.push(myApp.dataArray[i][0]); conteudo.push(myApp.dataArray[i][1]); console.log: ["2017-11-24", 1080000, "2017-11-25", -180000, "2017-11-26", 300000] in grafh appear "2017-11-24", 1080000 correcty, but no show up the rest values.I think that close ].
You should follow the formats that highcharts specifies in the documentation: highcharts.com/docs/chart-concepts/series So in this case it could look like this: [["2017-11-24", 1080000], ["2017-11-25", -180000], ["2017-11-26", 300000]]

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.