LineWidth不会更改谷歌图表

时间:2016-11-30 10:50:51

标签: javascript charts google-visualization line

如何更改此代码以使lineWidth生效?

<html>
<head>
  <!--Load the AJAX API-->
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
  <table>
    <tr>
      <td>k: </td>
      <td><input id="k" type="number" value="2.2" min="0" max="10" step="0.1" /></td>
    </tr>
    <tr>
      <td>lambda: </td>
      <td><input id="lambda" type="number" value="7.6" min="0" max="10" step="0.1" /></td>
    </tr>
  </table>

  <p id="message"> </p>
  <div id="chart_weights"></div>

  <script type="text/javascript">
    google.charts.load('current', {
      'packages': ['line']
    }); // load the visualisation API and corechart package
    google.charts.setOnLoadCallback(UpdateValues); // set a callback to run when the Google Visualization API is loaded

    // Callback that creates and populates a data table, instantiates the chart, passes in the data and draws it.
    function drawChart() {
      if (!google.visualization) {
        return;
      }
      // Create the data table for the symbol in question.
      var data = new google.visualization.DataTable();

      data.addColumn('number', '');
      data.addColumn('number', 'lambda');

      data.addRows(weight);
      var options = {
        lineWidth: 10,
        width: 550,
        height: 288,
        legend: {
          position: 'none'
        },
        colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f',
          '#f6c7b6'
        ]
      };
      //data.addRows(number);
      //console.log(type(data));

      var chart = new google.charts.Line(document.getElementById(
        'chart_weights'));
      chart.draw(data, options);
    }

    var weight = [];

    function UpdateValues() {
      weight = [];
      var k = document.getElementById("k").value;
      var lambda = document.getElementById("lambda").value;
      for (var x = 0.1; x < 20; x++) {
        weight.push([x, k * Math.pow(x / lambda, k - 1) * Math.exp(-
          Math.pow(x / lambda, k)) / lambda]);
        document.getElementById("message").innerHTML = weight;
      }
      drawChart();
    }

    UpdateValues();

    document.getElementById("k").addEventListener("click", function () {
      UpdateValues();
    });

    document.getElementById("lambda").addEventListener("click", function () {
      UpdateValues();
    });

  </script>
</body>

</html>

1 个答案:

答案 0 :(得分:2)

正在绘制的图表是材料图表

google.charts.Line - &gt; 'packages': ['line']

有许多选项根本不适用于材料图表 包括lineWidth

请参阅此问题 - &gt; Tracking Issue for Material Chart Feature Parity #2143

使用 Core 图表

google.visualization.LineChart - &gt; 'packages': ['corechart']

可以选择将 Core 图表的外观更改为与材料

类似

theme: 'material'