Does the graphics card render the Google graphics card disappear when it is updated?

I want to update google visualization line chart. My code was inspired by this article .

Here is my code:

http://jsfiddle.net/YCqyG/5/

You will see that when you click the "click" button, the chart suddenly disappears.


UPDATE: When I comment on this line, it works:

// this.element.html('');

And it does not work for a line chart. Any idea why it won't work for a line chart?

+2
source share
1 answer

, jQuery ; , $(element) $(element)[0] .. , jQuery , , :

  • add('LineChart', '#mileage') add('LineChart', 'mileage')
  • $(element)[0] document.getElementById(element)

:

  • div (.. this.element.html(''), .draw(newDataTable, opts) . gviz ( , ).
  • , , , , . , , , . , :

    function drawMyChart(dataTable) {
        // convert your dataTable to the right format
        // options here include loading from arrays, json representations of your datatable
        // or something more manual perhaps
        var opts = {height:50, width:50};
        var chart = new google.visualization.LineChart(document.getElementById('vis'));
        chart.draw(dataTable, opts);
    }
    
    function makeAjaxCall() {
        $.ajax({
            url: '/path/to/data/json',
            sucess: drawMyChart(a),
            dataType: 'json' // this is important, have it interpreted as json
        });
    }
    // html somewhere
    <div id='vis'></div>
    <input type='button' onclick='makeAjaxCall()'>Go</input>
    

, .

+1

Source: https://habr.com/ru/post/1713864/


All Articles