简体   繁体   中英

Google column chart bug with the drawing in Web app

In my web app there is a google chart that uses dataTable(jsonObject) to draw the graphs and I have bugged data. Here is my code of calling the function :

<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {

  function drawChart() {
             var myJson= $.ajax({
             url: "loadGraph.php",
             dataType:"json",
             async: false
            }).responseText;

  var visualization = new google.visualization.DataTable(myJson);

  var options = {
      title: "MyTitle",
      titleTextStyle: { fontSize: 16, bold: true },
      chartArea: { left: 32, right: 0,left: 52, width: 460, height: 180 },
      legend: { position: 'top' }
  }

  var chart = new google.visualization.ColumnChart(document.getElementById('chartDiv'));
  chart.draw(visualization , options);
 }

  google.setOnLoadCallback(drawVisualization);
  </script>

My graph was correctly drawed, but recently a bugs occured. Please help

Check my post on this matter : Google column chart visualization from json object bug in MVC 4 C#

There is a bug on this type of displaying the charts. The good part is that the solution is pretty slick. Replace the values for the chart with this regex ->

myJson = myJson.replace(/"v":"(\d+)"/g, '"v":$1');

This will fix the visualization ;] Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM