Also, these lines will cause problems in Internet Explorer:

var dataArray = [['x', 'y'], // <-- this comma will cause IE to throw a fit
];

which would prevent the chart from drawing in IE.

On Monday, March 3, 2014 8:22:52 AM UTC-5, Daniel LaLiberte wrote:
>
> Your ajax call is asynchronous, which means that it returns as soon as you 
> call it, and doesn't wait for the response back from the server.  The next 
> thing your code does is construct the data table and draw the chart.  But 
> there is no data yet because the ajax response is not back yet.
>
> You need to rearrange the code so you don't construct the data table and 
> draw the chart until after the ajax response is back.   One way you could 
> do that is to move those three lines that construct the data table and draw 
> the chart to the end of the 'success' handler *inside* of your ajax 
> request.    So the last few lines would look like this:
>
>              var options = {
>                        title: 'Company Performance',
>                        vAxis: {title: 'Year',  titleTextStyle: {color: 
> 'red'}}
>                     };
>          },
>
> var data = google.visualization.arrayToDataTable(dataArray);
>          var chart = new 
> google.visualization.LineChart(document.getElementById('chart_div'));
>         chart.draw(data, options); 
>         });
>     }
>
>
> On Mon, Mar 3, 2014 at 3:08 AM, Yoonchung Ock <[email protected]<javascript:>
> > wrote:
>
>> I wrote code, but it can't draw chart on web page....
>>
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
>> http://www.w3.org/TR/html4/loose.dtd";>
>> <html>
>>   <head>
>>     <script type="text/javascript" src="https://www.google.com/jsapi
>> "></script>
>>     <script language='javascript' src='
>> http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
>> '></script>
>>     <script type="text/javascript">
>>     
>>     google.load("visualization", "1", {packages:["corechart"]});
>>     google.setOnLoadCallback(drawChart);
>>     
>>     function drawChart () {
>>         $.ajax({
>>             url: 'data1',
>>             type: 'get',
>>             success: 
>>             function(txt){
>>             var dataArray = [['x', 'y'],
>>                              ];
>>             
>>             for (var i=0;txt!=null; i++){
>>             var txtArray = txt.split("\n");
>>  var tmpData = txtArray[i].split(" ");
>>    dataArray.push([tmpData[0], tmpData[1]]);
>>                                        document.write("dataArray" + i + 
>> ":" + dataArray + "<br>" + "<br>");
>>              }
>>             
>>             
>>             var options = {
>>                       title: 'Company Performance',
>>                       vAxis: {title: 'Year',  titleTextStyle: {color: 
>> 'red'}}
>>                    };
>>         },
>>         });
>> var data = google.visualization.arrayToDataTable(dataArray);
>>         var chart = new 
>> google.visualization.LineChart(document.getElementById('chart_div'));
>>         chart.draw(data, options);      
>>     }
>>
>>     </script>
>>   </head>
>>   
>>   
>>   <body>
>>     <div id="chart_div" style="width: 900px; height: 500px;"></div>
>>   </body>
>> </html>
>>
>>
>> the output is
>>
>> dataArray0:x,y,A,100 
>>
>> dataArray1:x,y,A,100 ,B,150 
>>
>> dataArray2:x,y,A,100 ,B,150 ,C,200 
>>
>> dataArray3:x,y,A,100 ,B,150 ,C,200 ,D,80 
>>
>> dataArray4:x,y,A,100 ,B,150 ,C,200 ,D,80 ,E,99 
>>
>> dataArray5:x,y,A,100 ,B,150 ,C,200 ,D,80 ,E,99 ,F,120
>>
>>
>> 2014-02-26 8:38 GMT+09:00 Daniel LaLiberte <[email protected]<javascript:>
>> >:
>>
>>>  If you are getting a Java Exception, that would be caused by something 
>>> on your server side. 
>>>
>>>
>>> On Tue, Feb 25, 2014 at 1:41 AM, Yoonchung Ock 
>>> <[email protected]<javascript:>
>>> > wrote:
>>>
>>>> I did that, but I got error
>>>> Java Exception Breakpoints
>>>> Unknown
>>>> null
>>>>
>>>> what's wrong?
>>>>
>>>> 2014년 2월 4일 화요일 오전 2시 29분 8초 UTC+9, asgallant 님의 말:
>>>>
>>>>> If you want to load a text file like that as the source of your data, 
>>>>> you need to use AJAX to pull the data into browser.  Many javascript 
>>>>> libraries offer AJAX tools to help you do this, here's an example using 
>>>>> jQuery:
>>>>>
>>>>> function drawChart () {
>>>>>     $.ajax({
>>>>>         url: '/path/to/mydata.txt',
>>>>>         type: 'text',
>>>>>         success: function (txt) {
>>>>>             var dataArray = [['column 1 label', 'column 2 label']];
>>>>>             var txtArray = txt.split('\n');
>>>>>             for (var i = 0; i < txtArray.length; i++) {
>>>>>                 // splits the text row by whitespace
>>>>>                 // assumes that the only whitespace in the row 
>>>>> separates column 1 from column 2
>>>>>                 var tmpData = txtArray[i].split(/\s+/);
>>>>>                 // insert the data into the data array
>>>>>                 // parsing the numbers as integers
>>>>>                 // you can use parseFloat instead, if you need 
>>>>> floating point numbers
>>>>>                 dataArray.push(tmpData[0], parseInt(tempData[1]));
>>>>>             }
>>>>>             
>>>>>             var data = google.visualization.
>>>>> arrayToDataTable(dataArray);
>>>>>             var chart = new google.visualization.LineChart(document.
>>>>> querySelector('#chart_div'));
>>>>>             chart.draw(data, {
>>>>>                 // chart options
>>>>>             });
>>>>>         }
>>>>>     });
>>>>> }
>>>>> google.load('visualization', '1', {packages:['corechart'], callback: 
>>>>> drawChart});
>>>>>
>>>>> On Monday, February 3, 2014 4:03:26 AM UTC-5, Yoonchung Ock wrote:
>>>>>>
>>>>>> I want to insert data from my server from text file for google chart. 
>>>>>> line chart.
>>>>>>
>>>>>> the text file is very simple...just two columns..
>>>>>>
>>>>>> ex.
>>>>>> A    12
>>>>>> B    123
>>>>>> C    32
>>>>>> D    32
>>>>>>
>>>>>> How can I read data from that text file and draw chart on web page 
>>>>>> with that data?
>>>>>> Help me please..
>>>>>>
>>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Google Visualization API" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to 
>>>> [email protected]<javascript:>
>>>> .
>>>>
>>>> To post to this group, send email to 
>>>> [email protected]<javascript:>
>>>> .
>>>> Visit this group at 
>>>> http://groups.google.com/group/google-visualization-api.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2>
>>>   - 978-394-1058
>>> [email protected] <javascript:>   5CC, Cambridge MA
>>> [email protected] <javascript:> 9 Juniper Ridge Road, Acton MA
>>>  
>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Google Visualization API" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/google-visualization-api/IKePuii7DXk/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected] <javascript:>.
>>>
>>> To post to this group, send email to 
>>> [email protected]<javascript:>
>>> .
>>> Visit this group at 
>>> http://groups.google.com/group/google-visualization-api.
>>> For more options, visit https://groups.google.com/groups/opt_out
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google Visualization API" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected]<javascript:>
>> .
>> To post to this group, send email to 
>> [email protected]<javascript:>
>> .
>> Visit this group at 
>> http://groups.google.com/group/google-visualization-api.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
> Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> 
>  - 978-394-1058
> [email protected] <javascript:>   5CC, Cambridge MA
> [email protected] <javascript:> 9 Juniper Ridge Road, Acton MA
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to