我尝试过多种方法,但似乎都没有改变我的图表。我正在通过文件上传数组,一切似乎都有效,甚至更改了defaultColor,但colorAxis似乎不起作用。你们(和女孩们)可以帮助我,我会很感激。感谢
/* CSV handling - START */
var processedData = [];
var continent = $('select[name="continents"] option:selected').val();
$.get('example.csv', function(data) {
processedData = $.csv.toArrays(data);
}, 'text');
/* CSV handling - END */
/* Google Charts */
google.charts.load('current', {
'packages':['geochart'],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
'mapsApiKey': //doesn't matter
});
google.charts.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable(processedData, false);
var options = {
sizeAxis: { minValue: 0, maxValue: 100 },
colorAxis: {colors: ['#e7711c', '#4374e0']},
region: continent,
width: '100%',
height: '100%',
backgroundColor: 'none'
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
/* Google Charts - End */
答案 0 :(得分:0)
请参阅Google Developer参考
https://developers.google.com/chart/interactive/docs/gallery/geochart#important
var options = { 地区:' 002',//非洲 colorAxis:{colors:['#00853f',' black','#e31b23']}, backgroundColor:'#81d4fa', datalessRegionColor:'#f8bbd0', defaultColor:'#f5f5f5', };
https://developers.google.com/chart/interactive/docs/gallery/geochart#coloring-your-chart
var options = { 地区:' IT', displayMode:' marker', colorAxis:{colors:[' green',' blue']} };
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
答案 1 :(得分:0)
使用评论中的数据,图表颜色似乎有效
建议删除sizeAxis
的选项
数据表中的值范围为100
到2313
(不是0
到100
),
图表将默认处理
请参阅以下工作代码段...
google.charts.load('current', {
callback: function () {
var processedData = [
['Country','Popularity'],
['HR',300.00],
['RU',100.00],
['FR',200.00],
['BR',2000.00],
['DZ',222.00],
['US',333.00],
['DE',555.00],
['DD',999.00],
['SZ',2313.00],
['AU',2222.00],
['BM',400.00],
['CA',322.00]
];
var data = google.visualization.arrayToDataTable(processedData);
var sizeRange = data.getColumnRange(1);
var options = {
colorAxis: {colors: ['#e7711c', '#4374e0']},
//region: continent,
width: '100%',
height: '100%',
backgroundColor: 'none'
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
},
packages: ['geochart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>