谷歌geochart标记大小和颜色

时间:2012-06-08 02:07:25

标签: javascript google-visualization

这是一个两部分问题。

首先,当绘制的点只是城市并且没有与它们相关的人口或大小时,有没有办法在Google的Geochart上更改标记的大小?我只是列出了没有附加价值的城市,所有Google的例子都附有某种人口。

例如,Google使用这段代码,其中标记的大小由人口反映。

function drawMarkersMap() {
  var data = google.visualization.arrayToDataTable([
    ['City',  'Population', 'Area'],
    ['Rome',     2761477,    1285.31],
    ['Milan',    1324110,    181.76],
    ['Naples',   959574,     117.27],
    ['Turin',    907563,     130.17],
    ['Palermo',  655875,     158.9],
    ['Genoa',    607906,     243.60],
    ['Bologna',  380181,     140.7],
    ['Florence', 371282,     102.41]
  ]);

有没有办法在没有按某种区域或人口设置的情况下更改标记大小?

其次,由于我没有标记大小的数字(只有城市名称),我该如何更改标记的颜色?根据我的理解,colorAxis是基于与被绘制城市相关的数字。

colorAxis: {colors: ['green', 'blue']}

以下是API文档https://developers.google.com/chart/interactive/docs/gallery/geochart

的链接

3 个答案:

答案 0 :(得分:1)

通过一些调整,你可以做到这一点。

查看我创建的一些示例:

http://cmoreira.net/interactive-world-maps-demo/svg-maps-of-the-states-in-usa/

要更改颜色,您应该执行以下操作:

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Country'); 
    data.addColumn('number', 'Value');
    data.addColumn({type:'string', role:'tooltip'});

    data.addRows([[{v:"Olympia  Washington",f:"Olympia"},1,"Capital city of the state of Washington"],[{v:"Seattle Washington",f:"Seattle"},2,"Largest city of the state of Washington"],[{v:"Spokane  Washington",f:"Spokane"},3,"Seconde Largest city of the state of Washington"],[{v:"Vancouver  Washington",f:"Vancouver"},4,"Fourth largest city of the state of Washington"],]);

var options = {   colorAxis: {minValue: 1, maxValue:4,  colors: ['#4A9928','#204DA8','#992F1A','#2292C9',]},

    (...)

因此,您递增一个数字,并提供尽可能多的不同颜色以匹配值。

要改变大小,我没有测试它,但是如果你玩这个值,我想类似的方法会起作用:

sizeAxis: {minValue: 1, maxValue:4,minSize:1,  maxSize: 4}

答案 1 :(得分:0)

据我所知,您无法直接定义Google Geochart中标记的颜色和大小。我建议你为自己的任务尝试另一种解决方案 - jVectorMap。使用markers参数定义标记时,您可以设置每个标记的大小和填充颜色,或使用markerDefaults定义默认参数。

答案 2 :(得分:0)

/*Code for geo chart configuration option*/
$scope.geoChartConfig = function (data, regionName) {
  $scope.chart = {};
  $scope.chart.type = "GeoChart";
  $scope.chart.data = data

  $scope.chart.options = {
    // width: 800,
    // height: 500,
    resolution: 'provinces', //code to set city wise data 
    region: regionName,
    sizeAxis: {
      // minValue: 1, //code to set min and max values in geo chart
      // maxValue: 4,
      minSize: 4, //code to set min and max marker size
      maxSize: 4
    },
    // markerOpacity:1,//code to set opacity or transparancy of chart
    displayMode: 'auto', //auto, chart will automatically detect data set whether it is regions or points
    keepAspectRatio: true, // code to set max size of chart according to div size html
    backgroundColor: '#eaf9ff',
    datalessRegionColor: 'white',
    defaultColor: '#f5f5f5',
    colorAxis: {
      colors: ['#1f77b4', '#55FF00', 'red'] //, '#ff0505'
    },
  };
}
相关问题