Google Visualization Column Chart set a data column from query as role: “Style”

前端 未结 1 1193
无人及你
无人及你 2021-01-22 01:34

I have a Google Visualization Column Chart from a query that works fine. I can set the a columns with a style role after the query by using the code snippet below. It adds a n

相关标签:
1条回答
  • 2021-01-22 02:08

    I'm not sure how you would add this to a column in the query but...

    using a DataView with a calculated column should work...

    Assumes the value you want to test is in the second column -- index 1

    var data = response.getDataTable();
    
    var view = new google.visualization.DataView(data);
    
    view.setColumns([0, 1, {
      type: "string",
      role: "style",
      calc: function (dataTable, rowIndex) {
        if (dataTable.getValue(rowIndex, 1) < 0.69) {
          return 'color: red;';
        } else if ((dataTable.getValue(rowIndex, 1) >= 0.69) && (dataTable.getValue(rowIndex, 1) <= 0.79)) {
          return 'color: yellow;';
        } else {
          return 'color: green;';
        }
      }
    }]);
    
    0 讨论(0)
提交回复
热议问题