ECharts 3.0 自定义美国各州地图颜色
ECharts 3.0 custom map colors for USA States
如何使用自定义颜色为美国地图中的每个州着色?
This is the ECharts demo data I am using.
例如,我想用红色标记共和党获胜的州,用蓝色标记民主党获胜的州。
According to the documentation 设置数据元素数组中的颜色应该可以做到。但是没有用。
我要this map (colored) to look like this map (duotone).
这可以通过在 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
中的数据来尝试
如何使用自定义颜色为美国地图中的每个州着色?
This is the ECharts demo data I am using.
例如,我想用红色标记共和党获胜的州,用蓝色标记民主党获胜的州。
According to the documentation 设置数据元素数组中的颜色应该可以做到。但是没有用。
我要this map (colored) to look like this map (duotone).
这可以通过在 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
中的数据来尝试