Hei,
Thanks for kind effort.
it gives
Microsoft JScript runtime error: Not a valid 2D array.
and it not displaying anything.
On Monday, March 4, 2013 6:32:56 PM UTC+1, asgallant wrote:
>
> I tested the code against the data sample you posted above. There is an
> error in the "foreach" line, because "foreach" isn't a javascript function
> (*facepalm*), it should be:
>
> for (var x in json[0]) {
>
> Other than that, everything works fine for me. When you try the code,
> what line is the error thrown on?
>
> On Monday, March 4, 2013 5:14:54 AM UTC-5, Sikandar Hayat wrote:
>>
>> Hei,
>>
>> In Google Chrome it shows
>> Uncaught SyntaxError: Unexpected token {
>>
>>
>>
>>
>> On Monday, March 4, 2013 11:04:49 AM UTC+1, Sikandar Hayat wrote:
>>>
>>> Hei,
>>>
>>> Thanks for the code but it is not showing any thing. it show page has
>>> error on line Char some where at var temp = [];
>>>
>>> Here is the code
>>>
>>>
>>>
>>> <script type="text/javascript">
>>> google.load('visualization', '1', { 'packages': ['corechart'] });
>>> google.setOnLoadCallback(drawChart);
>>>
>>> function drawChart() {
>>> var json = $.ajax({
>>> url: "
>>> http://localhost:8081/InvoicePortalReportService.svc/all?FromDate=20100101&TODATE=20131201&dateFormat=M
>>> ",
>>> dataType: "json",
>>> async: false
>>> }).responseText;
>>>
>>>
>>> var rows = [];
>>> var temp = [];
>>>
>>> foreach (x in json[0]) {
>>> temp.push(x);
>>> }
>>> rows.push(temp);
>>>
>>>
>>> for (var i = 0; i < json.length; i++) {
>>> rows.push([json[i][rows[0][0]], json[i][rows[0][1]],
>>> json[i][rows[0][2]]]);
>>> }
>>>
>>> var data = google.visualization.arrayToDataTable(rows);
>>>
>>> var chart = new
>>> google.visualization.LineChart(document.getElementById('chart_div'));
>>> chart.draw(data, { width: 400, height: 240 });
>>> }
>>>
>>> </script>
>>>
>>>
>>> On Monday, March 4, 2013 10:44:21 AM UTC+1, asgallant wrote:
>>>>
>>>> The easy way to parse is this:
>>>>
>>>> function drawChart() {
>>>> var json = $.ajax({
>>>> url: "
>>>> http://localhost:8081/InvoicePortalReportService.svc/all?FromDate=20100101&TODATE=20131201&dateFormat=M
>>>> ",
>>>> dataType: "json",
>>>> async: false,
>>>> }).responseText;
>>>>
>>>> var rows = [];
>>>> var temp = [];
>>>> foreach (var x in json[0]) {
>>>> temp.push(x);
>>>> }
>>>> rows.push(temp)
>>>>
>>>> for (var i = 0; i < json.length; i++) {
>>>> rows.push([json[i][rows[0][0]], json[i][rows[0][1]],
>>>> json[i][rows[0][2]]]);
>>>> }
>>>>
>>>> var data = google.visualization.arrayToDataTable(rows);
>>>>
>>>> // Instantiate and draw our chart, passing in some options.
>>>> var chart = new
>>>> google.visualization.PieChart(document.getElementById('chart_div'));
>>>> chart.draw(data, {
>>>> width: 400,
>>>> height: 240
>>>> });
>>>> }
>>>>
>>>> On Monday, March 4, 2013 3:55:34 AM UTC-5, Sikandar Hayat wrote:
>>>>>
>>>>> Hei,
>>>>>
>>>>> Thanks, How can I Parse for google chart. any idea?
>>>>>
>>>>> On Friday, March 1, 2013 4:03:53 PM UTC+1, asgallant wrote:
>>>>>>
>>>>>> The DataTable constructor expects input in a very specific
>>>>>> format<https://developers.google.com/chart/interactive/docs/reference#dataparam>,
>>>>>>
>>>>>> which your JSON string does not adhere to. You have two options to fix
>>>>>> this; either change things on your server-side to put the data in the
>>>>>> appropriate JSON format, or take the JSON as is and parse it into a
>>>>>> manually constructed DataTable.
>>>>>>
>>>>>> On Friday, March 1, 2013 7:40:58 AM UTC-5, Sikandar Hayat wrote:
>>>>>>>
>>>>>>> *my c# webservice code is*
>>>>>>> .........
>>>>>>> using System.Data;
>>>>>>>
>>>>>>> namespace QuickWebservice.InvoicePortalServiceApplication
>>>>>>> {
>>>>>>> // NOTE: You can use the "Rename" command on the "Refactor" menu
>>>>>>> to change the interface name "IInvoicePortalReportService" in both code
>>>>>>> and
>>>>>>> config file together.
>>>>>>> [ServiceContract]
>>>>>>> public interface IInvoicePortalReportService
>>>>>>> {
>>>>>>>
>>>>>>> [WebGet(UriTemplate =
>>>>>>> "all?fromDate={fromDate}&toDate={toDate}&dateFormat={dateFormat}",
>>>>>>> ResponseFormat = WebMessageFormat.Json)]
>>>>>>> List<IpClientInvoicesProcessedTotal>
>>>>>>> GetAllInvoicesProcessStatusTotal(string FromDate, string ToDate, string
>>>>>>> dateFormat);
>>>>>>>
>>>>>>> [WebGet(UriTemplate =
>>>>>>> "client?client={InvoiceProviderIdentifier_ClientId}&fromDate={fromDate}&toDate={toDate}&dateFormat={dateFormat}",
>>>>>>>
>>>>>>> ResponseFormat = WebMessageFormat.Json)]
>>>>>>> List<IpClientInvoicesProcessedTotal>
>>>>>>> GetClientInvoicesProcessStatusTotal(string
>>>>>>> InvoiceProviderIdentifier_ClientId, string FromDate, string ToDate,
>>>>>>> string
>>>>>>> dateFormat);
>>>>>>>
>>>>>>> ..................... its a webservice that return data
>>>>>>>
>>>>>>>
>>>>>>> *Url*:
>>>>>>> http://localhost:8081/InvoicePortalReportService.svc/all?FromDate=20100101&TODATE=20131201&dateFormat=M
>>>>>>>
>>>>>>> *Return data;*
>>>>>>>
>>>>>>> [{"ProcesssingTime":"jan.2011","Total_Fail":0,"Total_OK":1},{"ProcesssingTime":"feb.2011","Total_Fail":1,"Total_OK":0},{"ProcesssingTime":"jan.2012","Total_Fail":0,"Total_OK":1},{"ProcesssingTime":"feb.2012","Total_Fail":0,"Total_OK":1},{"ProcesssingTime":"mar.2012","Total_Fail":0,"Total_OK":1},{"ProcesssingTime":"apr.2012","Total_Fail":2,"Total_OK":0},{"ProcesssingTime":"jan.2013","Total_Fail":0,"Total_OK":5},{"ProcesssingTime":"feb.2013","Total_Fail":6,"Total_OK":32}]
>>>>>>>
>>>>>>>
>>>>>>> *Google chart Code*
>>>>>>>
>>>>>>>
>>>>>>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>>>>>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>>>>>> <html xmlns="http://www.w3.org/1999/xhtml">
>>>>>>> <head>
>>>>>>> <title></title>
>>>>>>>
>>>>>>> <script type="text/javascript"
>>>>>>> src="https://www.google.com/jsapi"></script>
>>>>>>> <script type="text/javascript"
>>>>>>> src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
>>>>>>> <script type="text/javascript"
>>>>>>> src="https://www.google.com/jsapi"></script>
>>>>>>> <script type="text/javascript"
>>>>>>> src="http://code.jquery.com/jquery-1.9.1.js"></script>
>>>>>>>
>>>>>>>
>>>>>>> <script type="text/javascript">
>>>>>>>
>>>>>>> // Load the Visualization API and the piechart package.
>>>>>>> google.load('visualization', '1', { 'packages': ['corechart']
>>>>>>> });
>>>>>>>
>>>>>>> // Set a callback to run when the Google Visualization API is
>>>>>>> loaded.
>>>>>>> google.setOnLoadCallback(drawChart);
>>>>>>>
>>>>>>>
>>>>>>> function drawChart() {
>>>>>>>
>>>>>>> var data = $.ajax({
>>>>>>> url:
>>>>>>> "http://localhost:8081/InvoicePortalReportService.svc/all?FromDate=20100101&TODATE=20131201&dateFormat=M",
>>>>>>> dataType: "json",
>>>>>>> async: false,
>>>>>>> }).responseText;
>>>>>>>
>>>>>>> // Create our data table out of JSON data loaded from
>>>>>>> server.
>>>>>>> var data = new google.visualization.DataTable(data);
>>>>>>>
>>>>>>> // Instantiate and draw our chart, passing in some options.
>>>>>>> var chart = new
>>>>>>> google.visualization.PieChart(document.getElementById('chart_div'));
>>>>>>> chart.draw(data, { width: 400, height: 240 });
>>>>>>> }
>>>>>>>
>>>>>>> </script>
>>>>>>>
>>>>>>> </head>
>>>>>>> <body>
>>>>>>> <div id="chart_div"></div>
>>>>>>> </body>
>>>>>>> </html>
>>>>>>>
>>>>>>> *
>>>>>>> *
>>>>>>>
>>>>>>> *
>>>>>>> *
>>>>>>>
>>>>>>> *Getting Table has no columns*
>>>>>>>
>>>>>>> *
>>>>>>> *
>>>>>>>
>>>>>>> *can you tell me why?*
>>>>>>>
>>>>>>> *
>>>>>>> *
>>>>>>>
>>>>>>> *thanks.*
>>>>>>>
>>>>>>>
--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.