Re: dynamic data for axis

101 views
Skip to first unread message

asgallant

unread,
Sep 26, 2012, 11:16:20 AM9/26/12
to google-visua...@googlegroups.com
Assuming mymap and mymapcount are populated correctly, your code looks like it would work as is.  Do your alert statements produce the results you expect?  If they do, then what happens when you try to draw a chart?

On Wednesday, September 26, 2012 2:02:27 AM UTC-4, taps wrote:
I have an array which I create from dynamic data.and I want to use this as haxis and yaxis.so how can I do that?
I am getting value for maymap array but for mymapcount m not getting.
my code is:

      var mymap=[];
      var mymapcount=[];
      
      function drawChart() {
      alert(mymap);
     
      alert(mymapcount);
      var dt=mymapcount[0];
      alert(dt);
        var data = google.visualization.arrayToDataTable([
          ['ID', '', '', 'frequncy', ''],
          
          [mymap[0], 1, 6, mymapcount[0],  6  ],
          [mymap[1],  2,  9,      9, 9],
          [mymap[2],   3,  3,      3, 3],
          [mymap[3],   4,  8,      8, 8],
          [mymap[4],   5,  2,      2, 2],
          ['helo',   6,  5,      5, 5]
        ]);

       

taps

unread,
Sep 27, 2012, 2:10:53 AM9/27/12
to google-visua...@googlegroups.com
I got that value but now I need to take that in loop.so how can I do that.I mean I want to create row based on loop like this:
for(var i=0;i<mymap.length;i++)
{
     var data = google.visualization.arrayToDataTable([
          ['ID', '', '', 'frequncy', ''],
          
          [mymap[i], 1, 6, mymapcount[i],  6  ]
        ]);
}
how should I create  that?

asgallant

unread,
Sep 27, 2012, 10:28:39 AM9/27/12
to google-visua...@googlegroups.com
Ahh, ok.  Here's how you would do it:

var dataArray [

    ['ID''''''frequncy''']
];
for (var 0mymap.lengthi++{
    dataArray.push([mymap[i]16mymapcount[i]6]);
}
var data google.visualization.arrayToDataTable(dataArray);

If you know the data types of your columns ahead of time, I suggest a slightly different approach, as it is less likely to encounter problems (as there are some data types that the arrayToDataTable method doesn't handle well):

var data google.visualization.arrayToDataTable();
data.addColumn('string''ID');
data.addColumn('number''');
data.addColumn('number''');
data.addColumn('number''frequency');
data.addColumn('number''');
for (var 0mymap.lengthi++{
    data.addRow([mymap[i]16mymapcount[i]6]);
}

asgallant

unread,
Sep 27, 2012, 10:30:18 AM9/27/12
to google-visua...@googlegroups.com
Sorry, I forgot to change one line in the second piece of code, it should be:

var data new google.visualization.DataTable();

data.addColumn('string''ID');
data.addColumn('number''');
data.addColumn('number''');
data.addColumn('number''frequency');
data.addColumn('number''');
for (var 0mymap.lengthi++{
    data.addRow([mymap[i]16mymapcount[i]6]);
}

taps

unread,
Sep 28, 2012, 1:38:20 AM9/28/12
to google-visua...@googlegroups.com
hey, thanks. The first piece of code is working but the second is not working.It doesn't show any chart.But I have used first one and its working fine.I want to ask another thing that can we put the labels as high,med and low on Y axis??
thanks again. 

asgallant

unread,
Sep 28, 2012, 10:35:29 AM9/28/12
to google-visua...@googlegroups.com
The second one you might need to change the data types in the column descriptions to fit your data.

As far as the y-axis labels go, no you can't format them like "high", "med", and "low".
Reply all
Reply to author
Forward
0 new messages