谷歌图表slantedText和min值不起作用

时间:2017-01-17 13:28:56

标签: javascript charts google-visualization

我正在使用谷歌图表。我想在x轴上设置文本,并且y轴上的最小值应为0。经过一些谷歌我把一些片段放在一起工作。

这是我的代码: -

var data = google.visualization.arrayToDataTable(loadDaysLeadGraphData);
 var options = {
   hAxis: {
     title: "Month",
     textPosition: 'out',
     slantedText: true,
      slantedTextAngle: 90
  },
  vAxis: {
    title: 'Revenue',
    minValue: 0,
    viewWindow: { min: 0 },
    format: '0',
  },
  height: 260,
  colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6']
};
var chart = new google.charts.Bar(document.getElementById('days-leads'));

chart.draw(data, options);

enter image description here

1 个答案:

答案 0 :(得分:4)

有很多选项根本不适用于材料图表,包括......

{hAxis,vAxis,hAxes.*,vAxes.*}.slantedText
{hAxis,vAxis,hAxes.*,vAxes.*}.slantedTextAngle
{hAxis,vAxis,hAxes.*,vAxes.*}.minValue

参见 - > Tracking Issue for Material Chart Feature Parity #2143

材料图表 - > google.charts.Bar - packages:['bar']

核心图表 - > google.visualization.ColumnChart - packages:['corechart']

但是,对于核心图表,有一个选项...

theme: 'material'

请参阅以下工作代码段...



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

function drawChart() {
  var loadDaysLeadGraphData = [
    ['Year', 'Value'],
    ['2005',  58],
    ['2006',  63],
    ['2007',  66],
    ['2008',  66],
    ['2009',  81],
    ['2010',  85],
    ['2011',  86],
    ['2012',  86],
    ['2013',  89],
    ['2014',  90],
    ['2015',  90]
  ];

  var data = google.visualization.arrayToDataTable(loadDaysLeadGraphData);
   var options = {
     hAxis: {
       title: "Month",
       textPosition: 'out',
       slantedText: true,
        slantedTextAngle: 90
    },
    vAxis: {
      title: 'Revenue',
      minValue: 0,
      viewWindow: { min: 0 },
      format: '0',
    },
    height: 260,
    colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6'],
    theme: 'material'
  };
  var chart = new google.visualization.ColumnChart(document.getElementById('days-leads'));

  chart.draw(data, options);
}

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="days-leads"></div>
&#13;
&#13;
&#13;