![](/img/trans.png)
[英]In Google Chart geochart Tooltip does't show all values and marker color has changed
[英]google geochart marker size and color
这是一个两部分的问题。
首先,当要绘制的点仅是城市且没有人口或规模与之相关时,是否可以更改Google Geochart上标记的大小? 我只是列出没有附加价值的城市,而所有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
通过一些调整,您可以做到这一点。
看看我创建的一些示例:
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}
据我从文档中了解到,您无法直接在Google Geochart中定义标记的颜色和大小。 我建议您尝试另一种解决方案-jVectorMap 。 使用markers
参数定义标记时,可以为每个标记设置大小和填充颜色,也可以使用markerDefaults
定义默认参数。
/*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'
},
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.