简体   繁体   English

如何更改angular-google-charts仪表图的针颜色?

[英]How to change the needle color of gauge chart of angular-google-charts?

I want to change the needle color of gauge chart.我想更改仪表图的针颜色。 在此处输入图片说明 I am using the following code to produce this gauge chart我正在使用以下代码生成此仪表图

 @ViewChild('googlechart', {static: true}) googlechart: GoogleChartComponent; public gaugeChart: { type: string; data: (string | { v: number; f: string })[][]; options: { width: number; height: number; greenFrom: number; greenTo: number; redFrom: number; redTo: number; yellowFrom: number; yellowTo: number; minorTicks: number; majorTicks: string[] } } = { type: 'Gauge', data: [ ['Water', {v: 78, f: '78%'}] ], options: { width: 500, height: 500, greenFrom: 50, greenTo: 100, redFrom: 0, redTo: 20, yellowFrom: 20, yellowTo: 50, minorTicks: 10, majorTicks: ['0%', '100%'] } };

Here needle color is red.这里针的颜色是红色。 I want to make it blue or green.我想让它变成蓝色或绿色。 How can I do it?我该怎么做?

Suppose we r going to show plan vs actual data from SQL database by using PHP Here $total_act is the actual value from SQL chart_div is my HTML div ID假设我们要使用 PHP 显示计划与 SQL 数据库中的实际数据 这里$total_act是 SQL 中的实际值chart_div是我的 HTML div ID

google.charts.load('current', {'packages': ['gauge']}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ['Label', 'Value'],
    ['TOTAL', {v: <?php print_r($total_act); ?>, f: '<?php print_r($total_act_lastday); ?>'} ],
  ]);


  var options = {
    width: screen.width, height: 200, greenFrom:20000, greenTo:40000, redFrom: 0, redTo:20000, minorTicks: 0, max:40000,min:0,majorTicks: ['0%', '', '', '', '100%'],
  };


  var container = document.getElementById('chart_div');
  var chart = new google.visualization.Gauge(container);

  google.visualization.events.addListener(chart, 'ready', function () {
    Array.prototype.forEach.call(container.getElementsByTagName('circle'), function(circle) {
      if (circle.getAttribute('fill') === '#4684ee') {
        circle.setAttribute('fill', '#000000');
      }
    });
    Array.prototype.forEach.call(container.getElementsByTagName('path'), function(path) {
      if (path.getAttribute('stroke') === '#c63310') {
        path.setAttribute('stroke', '#000000');
        path.setAttribute('fill', '#000000');
      }
    });
  });

  chart.draw(data, options);
});

Note : circle.setAttribute is for change round ball color path.setAttribute is for change needle color注意: circle.setAttribute 是改变圆球颜色 path.setAttribute 是改变针的颜色

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

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