简体   繁体   English

更改谷歌图表选项不起作用

[英]Change google charts options not working

I've created a google chart and the data is pulled from a database and structured to meet the requirements of the chart, however, for some reason, whenever I try change the options for the chart it just wont work.我已经创建了一个谷歌图表,数据是从数据库中提取的,并根据图表的要求进行结构化,但是,由于某种原因,每当我尝试更改图表的选项时,它都不起作用。 I need to move the legend to below the chart and make the point size on the chart 30 pixels.我需要将图例移动到图表下方,并使图表上的点大小为 30 像素。

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
    google.charts.load('current', {'packages':['line']});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {

      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Aspect');
      data.addColumn('number', 'Leaner');
      data.addColumn('number', 'Norm');
      data.addColumn('number', 'Grade');

      data.addRows([['Agility ', 11.5, 10, 11.5]]);
      var options = 
      {
        legend: { position: 'bottom' },
        chart: {title: 'Student Results'},
        legend:{position: 'bottom', textStyle: {color: 'black', fontSize: 16}},
        pointSize:30,
      };

      var chart = new google.charts.Line(document.getElementById('line_chart'));

      chart.draw(data, google.charts.Line.convertOptions(options));
    }
</script>

<div id="line_chart" style='width:calc(100% - 80px); height:400px; margin:auto;'></div>

Any suggestions on why the legend wont move or point size wont change, the chart data can have many aspects (x axis value), I need to point-size to change so that it wont look blank with just a aspect (x axis value)关于为什么图例不会移动或点大小不会改变的任何建议,图表数据可以有很多方面(x 轴值),我需要改变点大小,以便它不会看起来只有一个方面(x 轴值)

there are several options that simply don't work in Material charts 材料图表中,有些选项根本不起作用

and it appears Line requires two data points per series before drawing anything 看来Line在绘制任何内容之前需要每个系列两个数据点

I would recommend using 'corechart' instead 我建议使用'corechart'代替

there is an option for theme: 'material' to get the base look and feel close to a Material chart theme: 'material'有一个选项theme: 'material' ,使基本外观接近 材料

see following working snippet... 请参阅以下工作片段...

 google.charts.load('current', { callback: function () { var data = new google.visualization.DataTable(); data.addColumn('string', 'Aspect'); data.addColumn('number', 'Leaner'); data.addColumn('number', 'Norm'); data.addColumn('number', 'Grade'); data.addRows([['Agility 1', 11.5, 10, 11.5]]); var options = { chartArea: { width: '90%' }, height: 600, legend: { position: 'bottom', textStyle: { color: 'black', fontSize: 16 } }, pointSize: 30, theme: 'material', title: 'Student Results', vAxis: { viewWindow: { min: 0, max: 15 } }, width: '100%' }; var chart = new google.charts.Line(document.getElementById('line_chart')); chart.draw(data, google.charts.Line.convertOptions(options)); var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); }, packages:['line', 'corechart'] }); 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div>Core Chart</div> <div id="chart_div"></div> <div>Material Chart</div> <div id="line_chart"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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