地图上面加柱状图组

摘要:
如果(!coord&&!

地区地图阴影,加上单点柱状图组的展示

地图上面加柱状图组第1张

import echarts from 'echarts'
import '../../../../map-json/jiangmen'

const geoCoordMap = {
    市区1: [113.0989, 22.81677],
    市区2: [113.200601, 22.672211],
    市区3: [113.038584, 22.440247],
    市区4: [112.793414, 22.250713],
    市区5: [112.592262, 22.566286],
    市区6: [112.761795, 22.766104],
   市区7: [112.314051, 22.382956],
}

class ChartMap extends PureComponent {
    constructor(props) {
        super(props)
        this.state = {
            mapData: [
                ['市区1', 50, 20, 30],
                ['市区2', 10, 60, 30],
                ['市区3', 40, 10, 50],
                ['市区4', 30, 50, 70],
                ['市区5', 50, 50, 30],
                ['市区6', 60, 30, 30],
                ['市区7', 45, 90, 60],
            ],
            categoryType: ['数据1', '数据2', '数据3']
        }
        this.myChart = null
    }

    componentDidMount(){
        this.initEcharts()
        this.renderEachCity()
    }

    renderEachCity = () => {
        const { mapData, categoryType } = this.state
        const MyCubeRect = echarts.graphic.extendShape({
            shape: {
                x: 0,
                y: 0,
                 10, // 柱宽        
                zWidth: 10, // 阴影折角宽 
                zHeight: 0, // 阴影折角高
            },
            buildPath(ctx, shape) {
                const { api } = shape
                // 坐标系列
                const xAxisPoint = api.coord([shape.xValue, 0])
                const p0 = [shape.x, shape.y]
                const p1 = [shape.x - 5, shape.y]
                const p4 = [shape.x + 5, shape.y]
                const p2 = [xAxisPoint[0] - 5, xAxisPoint[1]]
                const p3 = [xAxisPoint[0] + 5, xAxisPoint[1]]
                // 描绘的图形 
                ctx.moveTo(p0[0], p0[1]) // 0
                ctx.lineTo(p1[0], p1[1]) // 1
                ctx.lineTo(p2[0], p2[1]) // 2
                ctx.lineTo(p3[0], p3[1]) // 3
                ctx.lineTo(p4[0], p4[1]) // 4
                ctx.lineTo(p0[0], p0[1]) // 0
                ctx.closePath()
            }
        })
        const MyCubeShadow = echarts.graphic.extendShape({
            shape: {
                x: 0,
                y: 0,
                 15,
                zWidth: 6,
                zHeight: 4,
            },
            buildPath(ctx, shape) {
                const { api } = shape
                const xAxisPoint = api.coord([shape.xValue, 0])
                const p1 = [shape.x - 5, shape.y]
                const p4 = [shape.x + 5, shape.y]
                const p6 = [shape.x + 5 + 8, shape.y - 4]
                const p7 = [shape.x - 5 + 8, shape.y - 4]
                const p3 = [xAxisPoint[0] + 5, xAxisPoint[1]]
                const p5 = [xAxisPoint[0] + 5 + 8, xAxisPoint[1] - 4]
              
                ctx.moveTo(p4[0], p4[1]) // 4
                ctx.lineTo(p3[0], p3[1]) // 3
                ctx.lineTo(p5[0], p5[1]) // 5
                ctx.lineTo(p6[0], p6[1]) // 6
                ctx.lineTo(p4[0], p4[1]) // 4
              
                ctx.moveTo(p4[0], p4[1]) // 4
                ctx.lineTo(p6[0], p6[1]) // 6
                ctx.lineTo(p7[0], p7[1]) // 7
                ctx.lineTo(p1[0], p1[1]) // 1
                ctx.lineTo(p4[0], p4[1]) // 4
                ctx.closePath()
            }
        })
        echarts.graphic.registerShape('MyCubeRect', MyCubeRect)
        echarts.graphic.registerShape('MyCubeShadow', MyCubeShadow)
        const option = {
            xAxis: [],
            yAxis: [],
            grid: [],
            series: [
                {
                    type: 'map',
                    map: '地市地图',
                    tooltip: {
                        show: false
                    },
                    label: {
                        show: true,
                        color: '#FFFFFF',
                        fontSize: 16
                    },
                    roam: false,
                    aspectScale: 1.5,
                    zoom: 1, // 地图初始大小
                    center: [112.699885, 22.36442], // 初始中心位置
                    // layoutCenter: ['50%', '55%'], // 地图位置
                    // layoutSize: '118%',
                    itemStyle: {
                        normal: {
                            borderColor: 'rgba(147, 235, 248, 0.6)',
                            borderWidth: 0.8,   
                            areaColor: '#ADDEFF',
                        },
                        emphasis: {
                            areaColor: '#ADDEFF'
                        }
                    },
                    zlevel: -100
                }
            ]
        }
 
        echarts.util.each(mapData, (dataItem, idx) => {
            const inflationData = [dataItem[1], dataItem[2], dataItem[3]]
            const geoCoord = geoCoordMap[dataItem[0]]// 获得城市的坐标
            const coord = this.myChart.convertToPixel('geo', geoCoord)// 转换坐标系上的点到像素坐标值。
            if (!coord && !geoCoord){
                return
            }
            //         const colorList = ['#369BFF', '#EBB34D', '#45BDE0', '#7D95FC', 
            // '#F19350', '#D94EC4', '#F26266', '#0283EA', '#16BA58', '#6E00FF', '#FFCE2F', '#F08C45']
            const colorList = ['#2364EE', '#F3A612', '#20C0B7', '#748CF3', '#EE8031', '#C52DAD', 
                '#F26266', '#0283EA', '#16BA58', '#6E00FF', '#FFCE2F', '#F08C45']
            const colorListShadow = ['#0346D3', '#EBB34D', '#14A599', '#7D95FC', '#F19350', '#862B77', 
                '#F26266', '#0283EA', '#16BA58', '#6E00FF', '#FFCE2F', '#F08C45']
            const index = `${idx}`
            option.xAxis.push({
                id: index,
                gridId: index,
                type: 'category',
                name: dataItem[0],
                nameTextStyle: {
                    color: '#fff',
                },
                nameLocation: 'middle',
                nameGap: 3,
                splitLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                axisLine: {
                    show: false
                },
                data: categoryType,
                z: 200
 
            })
            option.yAxis.push({
                id: index,
                gridId: index,
                splitLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                axisLine: {
                    show: false,
                },
                z: 200
            })
            option.grid.push({
                id: index,
                 30,
                height: 40,
                left: coord[0] - 15,
                top: coord[1] - 15,
                z: 200
            })
            option.series.push({
                type: 'custom',
                xAxisId: index,
                yAxisId: index,
                data: inflationData,
                z: 200,
                renderItem(params, api) {
                    if (!api.value(1)){
                        return null
                    }
                    const location = api.coord([api.value(0), api.value(1)])
                    return {
                        type: 'group',
                        children: [
                            {
                                type: 'MyCubeRect', // shape 属性描述了这个矩形的像素位置和大小
                                shape: {
                                    api,
                                    xValue: api.value(0), // 表示取出当前 dataItem 中第一个维度的数值
                                    yValue: api.value(1), 
                                    x: location[0],
                                    y: location[1]
                                
                                },
                                style: {
                                    fill: colorList[params.dataIndex], // 平面颜色
                                }
                            },
                            {
                                type: 'MyCubeShadow',
                                shape: {
                                    api,
                                    xValue: api.value(0),
                                    yValue: api.value(1),
                                    x: location[0],
                                    y: location[1]
                                },
                                style: {
                                    fill: colorListShadow[params.dataIndex], // 平面颜色
                                }
                            }]
                    }
                }
            })
        })
        this.myChart.resize()
        this.myChart.setOption(option)
    }

    initEcharts = () => {
        this.myChart = echarts.init(document.getElementById('chart-bar'))
        
        const option = {
            animation: false,
            // 地图背景颜色
            // backgroundColor: transition,
            tooltip: {
                trigger: 'axis'
            },
            z: 100,
            geo: {
                map: '地市地图',
                // silent: true,
                roam: false,
                aspectScale: 1.5,
                zoom: 1, // 地图初始大小
                center: [112.699885, 22.31442], // 初始中心位置
                label: {
                    normal: {
                        show: false,
                        textStyle: {
                            color: '#fff'
                        }
                    },
                    emphasis: {
                        show: false,
                        textStyle: {
                            color: '#fff'
                        }
                    }
                },
                // 地区块儿颜色
                itemStyle: {
                    normal: {
                        areaColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#409EFD'
                        },
                        {
                            offset: 1,
                            color: '#0866CC'
                        }
                        ], false),
                        borderColor: '#fff',
                        borderWidth: '2',
                    },
                    emphasis: {
                        areaColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#38D2FF'
                        },
                        {
                            offset: 1,
                            color: '#0396E8'
                        }
                        ], false),
                    }
                }
            },
            series: []
        }
        // 绘制图表
        this.myChart.setOption(option)
    }
    
    render() {
        return (
            <div styleName="chart-map-main"   />
        )
    }
}
ChartMap.defaultProps = {
}

ChartMap.propTypes = {
}

export default ChartMap

免责声明:文章转载自《地图上面加柱状图组》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇TSM lan-free原理及配置ant的安装下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Vue中使用Echarts实现立体柱状图(长方体)

预览: 代码: 页面部分: <template> <div ref="roadnumall"> <div ref="dom"></div> </div> </template> CSS部分: .roadnum-all { 100%; height:...

c语言系统函数——进程的创建

一 、 进程的创建    1.fork();创建一个独立的进程      pid_t fork(void);      使用这个命令会创建一个独立于父进程而且拷贝父进程全部存储空间的子进程      返回值有三种情况               1.父进程会返回子进程的进程号,pid>0              2.子进程会返回0;pid = 0...

小程序-formdata传参

项目背景,后端接口要求formData传参: 在util.js文件中封装转化函数,代码如下: const formatTime = date =>{ const year =date.getFullYear() const month = date.getMonth() + 1const day =date.getDate() con...

Puppeteer--基本使用

Puppeteer是谷歌官方出品的一个通过DevTools协议控制headless Chrome的Node库。 可以通过Puppeteer的提供的api直接控制Chrome模拟大部分用户操作来进行UI Test或者作为爬虫访问页面来收集数据。   一、环境和安装 Puppeteer推荐使用7.6版本以上的Node。另外headless Chrome本身对服...

POJ 3281 Dining (网络流之最大流)

题意:农夫为他的 N (1 ≤ N ≤ 100) 牛准备了 F (1 ≤ F ≤ 100)种食物和 D (1 ≤ D ≤ 100) 种饮料。每头牛都有各自喜欢的食物和饮料, 而每种食物或饮料只能分配给一头牛。最多能有多少头牛可以同时得到喜欢的食物和饮料? 析:是一个经典网络流的题,建立一个超级源点,连向每种食物,建立一个超级汇点,连向每种饮料,然后把每头牛...

C#窗体如何通过keybd_event()函数模拟键盘按键(组合键)产生事件

如何模拟键盘按键触发产生的事件,比如模拟按下Alt + F4 关闭当前程序,Ctrl+Shift 切换输入法等 可以通过win32api 键盘事件 keybd_event() 来实现 1、定义键盘按键对应得键码 #region bVk参数 常量定义 public const byte vbKeyLButton = 0x1;...