Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
im trying to build a candlestick graph using javascript and for my graph to be read correctly i need to convert data(object) to a long array in my code any help with that?
JavaScript
google.charts.load('current', {'packages':['corechart']});
     google.charts.setOnLoadCallback(drawChart);

 function drawChart() {

   var data = google.visualization.arrayToDataTable([

     ['Mon', 28638.9707, 28872.80078, 28627.76953, 28868.80078],
     ['Tue', 28553.33008, 28716.31055, 28500.35938, 28634.88086],
     ['Wed', 28465.5, 28708.01953, 28418.63086, 28703.38086],
     ['Thu', 28639.17969, 28685.5, 28565.2793, 28583.67969],
     ['Fri', 28556.14063, 28866.17969, 28522.50977, 28745.08984],
     ['G', 28851.9707, 28988.00977, 28844.31055, 28956.90039],
     ['f', 28977.51953, 29009.07031, 28789.09961, 28823.76953],
     ['d', 28869.00977, 28909.91016, 28819.42969, 28907.05078],
     ['f', 28895.5, 29054.16016, 28872.26953, 28939.66992],
     ['r', 28901.80078, 29127.58984, 28897.34961, 29030.2207],
     ['t', 29131.94922, 29300.32031, 29131.94922, 29297.64063],
     ['y', 29313.31055, 29373.61914, 29289.91016, 29348.09961],
     ['w', 29269.05078, 29341.21094, 29146.4707, 29196.03906],
     ['q', 29263.63086, 29320.19922, 29172.25977, 29186.26953],
     ['a', 29111.01953, 29190.4707, 28966.98047, 29160.08984],
     ['s', 29230.39063, 29288.78906, 28843.31055, 28989.73047],
     ['a', 28542.49023, 28671.78906, 28440.4707, 28535.80078],
     ['j',  28594.2793, 28823.23047, 28575.75, 28722.84961],
     ['k', 28820.5293, 28944.24023, 28728.18945, 28734.44922],
     ['l', 28640.16016, 28879.71094, 28489.75977, 28859.43945]


     // Treat first row as data as well.
   ], true);

   var options = {
     legend:'none',
     seriesType: 'candlesticks',

   };

   var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));

   chart.draw(data, options);
 }


What I have tried:

var keys = [];

for (var number in data) {
  if(data.hasOwnProperty(number)){
    keys.push(number)
  }
}
Posted
Comments
F-ES Sitecore 6-Apr-20 6:29am    
What data would be in the array?
goo hey 6-Apr-20 7:06am    
so the data is in columns , first one is date, open , high,low and close.. from that i want the open and close colums data as in the array. thanks for the relpy

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900