javascript - 如何更改谷歌图表地理 map 中的默认颜色?

标签 javascript google-visualization geomap

我想将图表区域的默认黄色更改为用户定义的颜色。我只能更改标记颜色。我使用此代码生成图表数据。

         dataTable = new google.visualization.DataTable();
         dataTable.addRows(4);
         dataTable.addColumn('number', 'LATITUDE', 'Latitude');
         dataTable.addColumn('number', 'LONGITUDE', 'Longitude');
         dataTable.addColumn('number', 'Ticket', 'Value'); 
         dataTable.addColumn('string', 'HOVER', 'HoverText');

         dataTable.setValue(0,0,12.9715987);
         dataTable.setValue(0,1,77.5945627);
         dataTable.setValue(0,2,43);
         dataTable.setValue(0,3,"Banglore");

         dataTable.setValue(1,0,22.642664);
         dataTable.setValue(1,1,88.439122);
         dataTable.setValue(1,2,66);
         dataTable.setValue(1,3,"Kolkatta");

         dataTable.setValue(2,0,13.0826802);
         dataTable.setValue(2,1,80.2707184);
         dataTable.setValue(2,2,54);
         dataTable.setValue(2,3,"Chennai");

         dataTable.setValue(3,0,9.9252007);
         dataTable.setValue(3,1,78.1197754);
         dataTable.setValue(3,2,64);
         dataTable.setValue(3,3,"Madurai");

enter image description here

如何更改区域、背景和工具提示颜色?请帮助我

最佳答案

有一个 ticket on github for this

基本上,下面的代码设置了您需要的选项

var options = {};
  options['region'] = 'US';
  options['resolution'] = 'provinces';
  options['colorAxis'] = { minValue : 0, maxValue : 1, colors : ['#FF0000','#0000FF']};
  options['backgroundColor'] = '#FFFFFF';
  options['datalessRegionColor'] = '#E5E5E5';
  options['width'] = 556;
  options['height'] = 347;
  options['legend'] = 'none';

  var geochart = new google.visualization.GeoChart(
      document.getElementById('visualization'));
  geochart.draw(geoData, options);

这也包含在 official docs

backgroundColor

The background color for the main area of the chart. Can be either a simple HTML color string, for example: 'red' or '#00cc00', or an object with the following properties.

Type: string or object Default: white

backgroundColor.fill

The chart fill color, as an HTML color string.

Type: string Default: white

backgroundColor.stroke

The color of the chart border, as an HTML color string.

Type: string Default: '#666'

backgroundColor.strokeWidth

The border width, in pixels.

Type: number Default: 0

关于javascript - 如何更改谷歌图表地理 map 中的默认颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30482467/

相关文章:

google-maps - 如何将可视化商业地理 map 与谷歌地图结合使用?

javascript - 如何使用 codemirror 启用代码提示?

javascript - 获取表格列的总和并添加到谷歌图表

javascript - 为什么 John Resig 的 JavaScript 需要第二个闭包?

javascript - 通过 Google Charts 在柱形图中添加描述?

javascript - 在 JS 中使用 Bootstrap 颜色

javascript - Google Geomap API 更改区域选项 onClick()

visualization - google.load 导致 dom/screen 为空

Javascript:从列表中获取选定的选项并将其粘贴到标签标记上

javascript - html canvas在网页上的位置