If you modify your server code to send the data like this:

{
    "cols": [
        {"label": "Date", "type": "date"},
        {"label": "Buy", "type": "number"},
        {"label": "Sell", "type": "number"},
    ],
    "rows": [
        ["Date(2012,10,28)",15,14],
        ["Date(2012,10,29)",55,51],
        ["Date(2012,10,30)",53,49]
    ]
}

and then create the DataTable like this:

var data = new google.visualization.DataTable(obj);

You don't have to worry about converting the dates from strings to Date 
objects.

On Tuesday, November 27, 2012 6:32:57 PM UTC-5, Dragomir Haralambiev wrote:
>
> I modify the server-side code. Here is new code:
>             var jsonData = $.ajax({
>                 url: "js/chart.pl",
>                 dataType: "json",
> contentType: "application/json",
>                 async: false
>             }).responseText;
>
>             var obj = jQuery.parseJSON(jsonData);
> var data = new google.visualization.DataTable();
> data.addColumn('date', 'Date');
> data.addColumn('number', 'Buy');
> data.addColumn('number', 'Sell');
> data.addRows(obj); 
> Server send:
>
> [["Date(2012,10,28)",15,14],["Date(2012,10,29)",55,51],["Date(2012,10,30)",53,49]]
>
>
> I receive follow Error:
> Type mismatch. Value Date(2012,10,28) does not match type date in column 
> index 0
>
> How to convert Date(2012,10,28) to date type?
>
> Best regards,
> Dragomir
>
>
>
> 27 ноември 2012, вторник, 23:17:04 UTC+2, asgallant написа:
>>
>> Can you modify the server-side code?  If so, then the best method might 
>> be to build the DataTable as a JSON object (structure linked to in the post 
>> above), which you can feed directly to the DataTable constructor.  There 
>> are examples of this in PHP on the forum here; doing it in perl would 
>> probably be similar.
>>
>> On Tuesday, November 27, 2012 2:37:10 PM UTC-5, Dragomir Haralambiev 
>> wrote:
>>>
>>> Hi.
>>> Thanks for your replay.
>>> You right if obj is generate from javascript.
>>> What I do if obj is generate from AJAX like this:
>>>             var jsonData = $.ajax({
>>>                 url: "js/chart.pl",
>>>                 dataType: "json",
>>> contentType: "application/json",
>>>                 async: false
>>>             }).responseText;
>>>
>>>             var obj = jQuery.parseJSON(jsonData);
>>>
>>>
>>> Best regards,
>>> Fragomir
>>> 27 ноември 2012, вторник, 18:55:07 UTC+2, asgallant написа:
>>>>
>>>> The 
>>>> arrayToDataTable<https://developers.google.com/chart/interactive/docs/reference#google.visualization.arraytodatatable>method
>>>>  doesn't handle dates properly; your dates are being input as 
>>>> strings.  To fix this, you will have to manually construct the DataTable 
>>>> (or use the 
>>>> json<https://developers.google.com/chart/interactive/docs/reference#dataparam>format).
>>>>
>>>> Here's one way you could do it manually:
>>>>
>>>> var obj = [
>>>>     [new Date(2012,10,2),15,14],
>>>>     //....
>>>> ];
>>>> var data = new google.visualization.DataTable();
>>>> data.addColumn('date', 'Date');
>>>> data.addColumn('number', 'Buy');
>>>> data.addColumn('number', 'Sell');
>>>> data.addRows(obj);
>>>>
>>>> Note that the format for the date is as a Date object and not a string 
>>>> when using this method.
>>>>
>>>> On Tuesday, November 27, 2012 5:37:44 AM UTC-5, Dragomir Haralambiev 
>>>> wrote:
>>>>>
>>>>> I'm trying to test the Google Chart, but I receive follow error:
>>>>> "One or more participants failed to draw().
>>>>> The filter cannot operate on a column of type string. Column type must 
>>>>> be one of: number, date, datetime or timeofday. Column role must be 
>>>>> domain, 
>>>>> and correlate to a continuous axis."
>>>>>
>>>>> What am I doing wrong?
>>>>>  
>>>>>
>>>>>
>>>>> <script type="text/javascript" src="
>>>>> https://www.google.com/jsapi";></script>
>>>>>     <script type="text/javascript">
>>>>>
>>>>>          google.load('visualization', '1.0', 
>>>>> {'packages':['controls']});
>>>>>         google.setOnLoadCallback(drawDashboard);
>>>>>     
>>>>>       function drawDashboard() {
>>>>>  var obj = 
>>>>> [["Date","buy","sell"],["Date(2012,10,2)",15,14],["Date(2012,10,3)",55,51],["Date(2012,10,4)",53,49]];
>>>>>         var dataa = google.visualization.arrayToDataTable(obj);
>>>>>         var dashboard = new 
>>>>> google.visualization.Dashboard(document.getElementById('dashboard_div'));
>>>>>
>>>>>         var donutRangeSlider = new 
>>>>> google.visualization.ControlWrapper({
>>>>>           'controlType': 'ChartRangeFilter',
>>>>>           'containerId': 'filter_div',
>>>>>           'options': {
>>>>>      'filterColumnIndex': 0,
>>>>>      'ui': {
>>>>>       'chartType': 'LineChart',
>>>>>       'chartOptions': {
>>>>>         'chartArea': {'width': '90%'},
>>>>>         'hAxis': {'baselineColor': 'none'}
>>>>>       },
>>>>>       'chartView': { 'columns': [0, 1] },
>>>>>       'minRangeSize': 86400000
>>>>>     }
>>>>>           },
>>>>>         });
>>>>>
>>>>>         var lineChart = new google.visualization.ChartWrapper({
>>>>>           'chartType': 'LineChart',
>>>>>           'containerId': 'chart_div',
>>>>>           'options': {
>>>>>                 title: 'Title',
>>>>>           }
>>>>>         });
>>>>>
>>>>>         dashboard.bind(donutRangeSlider, lineChart);
>>>>>         dashboard.draw(dataa);
>>>>>       }    
>>>>> </script>
>>>>>
>>>>> Best regards,
>>>>> Dragomir
>>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-visualization-api/-/CrlEqhFSSZkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to