Annotation Chart from JSON data -

83 views
Skip to first unread message

Robert on G

unread,
May 19, 2017, 10:45:50 AM5/19/17
to Google Visualization API
I am using JSON data to add rows. Following this along in Chrome I can see chartdata getting the 'qp' node filled with the rows from my dataset. But in the end I get "table has no rows". Been at this for a while and I have run out of options to pursue.

The dataTableToCsv result does not give me any clues either.

What am I missing here?


google.charts.load('current', { 'packages': ['annotationchart'] });
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
    var chartdata = new google.visualization.DataTable();
    chartdata.addColumn('datetime', 'Date');
    chartdata.addColumn('number', 'Chan 1');
    chartdata.addColumn('number', 'Chan 4');

    $.getJSON('/Members/chartGet7010s', function (data) {
        $.each(data, function (i, item) {
            var rdDate = parseJsonDate(item.readingDate);
            chartdata.addRow([new Date(rdDate.getFullYear(), rdDate.getMonth(), rdDate.getDate(), rdDate.getHours(), rdDate.getMinutes(), rdDate.getSeconds()), parseFloat(item.Chan1), parseFloat(item.Chan4)]);            
        });
    });

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

    var csvdata = new google.visualization.dataTableToCsv(chartdata);
    console.log(csvdata);
    var options = {
        displayAnnotations: true
    };

    chart.draw(chartdata, options);
}

function parseJsonDate(jsonDateString) {
    return new Date(parseInt(jsonDateString.replace('/Date(', '')));
};
annotationchartCSV.PNG
Reply all
Reply to author
Forward
0 new messages