簡體   English   中英

Google Charts:如何在散點圖中設置一個點的樣式?

[英]Google Charts: how do I style one point in a scatter chart?

通過使用散點圖API在谷歌圖表,連同這個例子就如何改變形狀/顏色/等的一個點,我一直在努力做到這一點。 然而,雖然應該單獨設置樣式的點出現了,但它不會根據給定的樣式而改變。 這是一個小例子:

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

  function drawChart () {

    var data = new google.visualization.DataTable();
    data.addColumn('number', 'X-axis');
    data.addColumn('number', 'A data');
    data.addColumn({'type': 'string', 'role': 'style'});
    data.addColumn('number', 'B data');
    data.addColumn({'type': 'string', 'role': 'style'});

    data.addRows([
      [1.1, 12, null, null, null],
      [1.3, 13, null, null, null],
      [0.1, null, null, 0, null],
      [0.3, null, null, 3, null],
      [1.2, 13, 'point {size: 13; shape-type: star; fill-color: #00ffff;}', null, null],
      [0.2, null, null, 4, 'point {size: 13; shape-type: star; fill-color: #ff00ff;}'],

    ]);

    var options = {
      width: 800,
      height: 500,
      chart: {
        title: 'Small example'
      },
      hAxis: {title: 'X-axis'},
      vAxis: {title: 'Y-axis'}
    };

    var chart = new google.charts.Scatter(document.getElementById('example_scatter_chart'));

    chart.draw(data, google.charts.Scatter.convertOptions(options));
  }
  </script>
  </head>
  <body>
    <div id="example_scatter_chart" style="width: 500px; height: 500px;"></div>
  </body>
</html>

我在這里缺少什么?

role: 'style'材質圖表上根本不起作用
google.charts.Scatter

需要使用'packages':['corechart']google.visualization.ScatterChart

請參閱以下工作片段...

 google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart () { var data = new google.visualization.DataTable(); data.addColumn('number', 'X-axis'); data.addColumn('number', 'A data'); data.addColumn({'type': 'string', 'role': 'style'}); data.addColumn('number', 'B data'); data.addColumn({'type': 'string', 'role': 'style'}); data.addRows([ [1.1, 12, null, null, null], [1.3, 13, null, null, null], [0.1, null, null, 0, null], [0.3, null, null, 3, null], [1.2, 13, 'point {size: 13; shape-type: star; fill-color: #00ffff;}', null, null], [0.2, null, null, 4, 'point {size: 13; shape-type: star; fill-color: #ff00ff;}'] ]); var options = { width: 800, height: 500, chart: { title: 'Small example' }, hAxis: {title: 'X-axis'}, vAxis: {title: 'Y-axis'}, theme: 'material' }; var chart = new google.visualization.ScatterChart(document.getElementById('example_scatter_chart')); chart.draw(data, options); }
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="example_scatter_chart"></div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM