Google Chart vAxis values are not showing

前端 未结 4 1696
醉话见心
醉话见心 2021-01-15 00:02

I am working on various graphs and I am showing multiple graphs in a single page. Somehow vAxis values are not showing on some graphs but it showing in some independent (we

4条回答
  •  长情又很酷
    2021-01-15 00:40

    most likely, the chart's container is hidden when it is drawn.
    it should be made visible beforehand.

    see following working snippet, which produces the same result.
    the chart's container is hidden, then shown on the chart's 'ready' event.
    as a result, the vAxis labels are missing.

    google.charts.load('current', {
      packages: ['corechart']
    }).then(function () {
      var data = new google.visualization.DataTable({
        cols: [
          {label: 'x', type: 'string'},
          {label: 'y0', type: 'number'},
          {label: 'y1', type: 'number'},
          {label: 'y2', type: 'number'},
          {label: 'y3', type: 'number'},
        ],
        rows: [
          {c:[{v: 'Column 1'}, {v: 9145.6}, {v: 1000.4}, {v: 0}, {v: 900.4}]},
          {c:[{v: 'Column 2'}, {v: 8123.1}, {v: 0}, {v: 0}, {v: 0}]},
          {c:[{v: 'Column 3'}, {v: 7030.7}, {v: 200.3}, {v: 999.75}, {v: 0}]}
        ]
      });
    
      var options = {
        width: 1410,
        height: 400,
        legend: {position: 'right'},
        bar: {groupWidth: '75%'},
        isStacked: 'true',
        vAxis: {
          minValue: 0,
          title: 'Count',
          textStyle: {fontSize: 7}
        }
      };
    
      var container = document.getElementById('chart_div');
      var chart = new google.visualization.ColumnChart(container);
      google.visualization.events.addListener(chart, 'ready', function () {
        container.className = '';
      });
      chart.draw(data, options);
    });
    .hidden {
      display: none;
      visibility: hidden;
    }
    
    


    when the container is hidden, the chart cannot properly size or place chart elements.
    ensuring the chart is visible before drawing will ensure proper rendering.

    see following working snippet...

    google.charts.load('current', {
      packages: ['corechart']
    }).then(function () {
      var data = new google.visualization.DataTable({
        cols: [
          {label: 'x', type: 'string'},
          {label: 'y0', type: 'number'},
          {label: 'y1', type: 'number'},
          {label: 'y2', type: 'number'},
          {label: 'y3', type: 'number'},
        ],
        rows: [
          {c:[{v: 'Column 1'}, {v: 9145.6}, {v: 1000.4}, {v: 0}, {v: 900.4}]},
          {c:[{v: 'Column 2'}, {v: 8123.1}, {v: 0}, {v: 0}, {v: 0}]},
          {c:[{v: 'Column 3'}, {v: 7030.7}, {v: 200.3}, {v: 999.75}, {v: 0}]}
        ]
      });
    
      var options = {
        width: 1410,
        height: 400,
        legend: {position: 'right'},
        bar: {groupWidth: '75%'},
        isStacked: 'true',
        vAxis: {
          minValue: 0,
          title: 'Count',
          textStyle: {fontSize: 7}
        }
      };
    
      var container = document.getElementById('chart_div');
      var chart = new google.visualization.ColumnChart(container);
      chart.draw(data, options);
    });
    
    

提交回复
热议问题