如何使用自定义颜色为美国地图中的每个州着色?
This is the ECharts demo data I am using
例如,我想为共和党赢得红色和蓝色民主党赢得的州着色。
According to the documentation设置数据元素数组中的颜色应该这样做。但是没有用。
答案 0 :(得分:0)
这可以通过设置visualMap
数据中的颜色来实现。
我玩过一点,你可以做以下事情:
将visualMap
设置为0到1的范围,使其成为二进制,并将每个值分配给民主党或共和党人。
visualMap: {
left: 'right',
min: 0,
max: 1,
inRange: {
color: ['#DE0100', '#031BBB']
},
text: ['Republican','Democrat'],
calculable: true
},
接下来,在data
中,将每个州的值设置为0
或1
。
data:[
{name: 'Alabama', value: 0},
{name: 'Alaska', value: 0},
{name: 'Arizona', value: 0},
{name: 'Arkansas', value: 0},
{name: 'California', value: 1},
{name: 'Colorado', value: 1},
{name: 'Connecticut', value: 1},
{name: 'Delaware', value: 1},
{name: 'District of Columbia', value: 0},
{name: 'Florida', value: 0},
{name: 'Georgia', value: 0},
{name: 'Hawaii', value: 0},
{name: 'Idaho', value: 0},
{name: 'Illinois', value: 1},
{name: 'Indiana', value: 0},
{name: 'Iowa', value: 0},
{name: 'Kansas', value: 0},
{name: 'Kentucky', value: 0},
{name: 'Louisiana', value: 0},
{name: 'Maine', value: 1},
{name: 'Maryland', value: 1},
{name: 'Massachusetts', value: 1},
{name: 'Michigan', value: 0},
{name: 'Minnesota', value: 1},
{name: 'Mississippi', value: 0},
{name: 'Missouri', value: 0},
{name: 'Montana', value: 0},
{name: 'Nebraska', value: 0},
{name: 'Nevada', value: 1},
{name: 'New Hampshire', value: 1},
{name: 'New Jersey', value: 1},
{name: 'New Mexico', value: 1},
{name: 'New York', value: 1},
{name: 'North Carolina', value: 0},
{name: 'North Dakota', value: 0},
{name: 'Ohio', value: 0},
{name: 'Oklahoma', value: 0},
{name: 'Oregon', value: 1},
{name: 'Pennsylvania', value: 0},
{name: 'Rhode Island', value: 1},
{name: 'South Carolina', value: 0},
{name: 'South Dakota', value: 0},
{name: 'Tennessee', value: 0},
{name: 'Texas', value: 0},
{name: 'Utah', value: 0},
{name: 'Vermont', value: 1},
{name: 'Virginia', value: 1},
{name: 'Washington', value: 1},
{name: 'West Virginia', value: 0},
{name: 'Wisconsin', value: 0},
{name: 'Wyoming', value: 0},
{name: 'Puerto Rico', value: 0}
]
您可以通过复制粘贴map demo
中的数据来试用它