在echart中,我的地图上显示城市的维度,如何让其不显示维度而显示自定义数据
时间: 2023-06-04 17:07:24 浏览: 99
您可以使用 echarts 自带的 formatter 属性来自定义显示的数据。具体做法如下:
1. 在 series 中设置 name 属性为需要显示的自定义数据,如 city。
2. 在 xAxis 和 yAxis 中设置 type 为 'category',表示横纵坐标轴上的数据类型为分类型,而非数值型。
3. 在 visualMap 中设置 type 为 'piecewise',表示可视化的映射方式为离散型。
4. 在 visualMap 中通过 pieces 属性来指定每个value范围对应的color值和label值。
5. 在 series 中通过 itemStyle 中的 normal 属性来配置每个图形项的样式。
以下是代码示例:
```
option = {
tooltip: {},
xAxis: {
type: 'category',
},
yAxis: {
type: 'category',
},
visualMap: {
type: 'piecewise',
pieces: [
{value: 'Beijing', label: '北京', color: '#00BFFF'},
{value: 'Shanghai', label: '上海', color: '#9400D3'},
{value: 'Guangzhou', label: '广州', color: '#FF8C00'},
{value: 'Shenzhen', label: '深圳', color: '#DC143C'}
],
orient: 'horizontal',
left: 'center',
bottom: '10%'
},
series: [{
name: 'city',
type: 'scatter',
data: [
['Beijing', '39.9'],
['Shanghai', '31.2'],
['Guangzhou', '28.8'],
['Shenzhen', '23.9']
],
itemStyle: {
normal: {
opacity: 0.8,
shadowBlur: 10,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}]
};
```
以上示例中,我们通过将 type 属性设置为 'category',来指定 xAxis 和 yAxis 上的数据类型为分类型,然后在 visualMap 中通过 pieces 属性来指定每个value范围对应的color值和label值。最后在 series 中通过 name 属性来指定我们需要显示的自定义数据,即城市名称。