vue echart 散点图画矩形区域

vue echart 散点图画矩形区域

其实没打算写这部分东西来着,但是当时做的时候没找到合适的方式,看到别人写的博客总是觉得博客这种东西就是自己写完之后自己用,能分享一下就分享一下吧。

其实方法很简单,只不过没有接触过的人可能觉得会有点难度,不是难,是没思路,点一下子就好了。

先上图,当时我想做的就是类似于这个样子:

在这里插入图片描述
其实就是在散点图上添加这个蓝色的小方块。

做法其实就是在 echart 上画线,一个小方块四条线组成,然后一条线又两个坐标确定。

https://echarts.apache.org/zh/option.html#series-scatter.markLine

上面是官网地址,详细的可以去这里面查看。

然后代码我就不上了,然后最后拼起来的option大体是这个样子。

{
    "grid":{
        "top":0,
        "left":0,
        "right":0,
        "bottom":0
    },
    "xAxis":{
        "show":false,
        "data":[
            -4,
            -3,
            -2,
            -1,
            0,
            1,
            2,
            3,
            4,
            5
        ],
        "type":"value",
        "splitLine":{
            "show":true
        },
        "max":10
    },
    "yAxis":{
        "type":"value",
        "show":false,
        "data":[
            -4,
            -3,
            -2,
            -1,
            0,
            1,
            2,
            3,
            4,
            5
        ],
        "max":10
    },
    "series":[
        {
            "symbolSize":1,
            "color":"#fff",
            "data":[
                [
                    0,
                    0
                ]
            ],
            "type":"scatter",
            "markLine":{
                "symbol":[
                    "none",
                    "none"
                ],
                "silent":true,
                "animation":false,
                "itemStyle":{
                    "normal":{
                        "lineStyle":{
                            "type":"solid",
                            "width":1,
                            "opacity":1
                        },
                        "label":{
                            "show":false,
                            "position":"left"
                        }
                    }
                },
                "data":[
                    [
                        {
                            "coord":[
                                1,
                                9
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        },
                        {
                            "coord":[
                                1,
                                7
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        }
                    ],
                    [
                        {
                            "coord":[
                                1,
                                7
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        },
                        {
                            "coord":[
                                3,
                                7
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        }
                    ],
                    [
                        {
                            "coord":[
                                3,
                                7
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        },
                        {
                            "coord":[
                                3,
                                9
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        }
                    ],
                    [
                        {
                            "coord":[
                                3,
                                9
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        },
                        {
                            "coord":[
                                1,
                                9
                            ],
                            "itemStyle":{
                                "normal":{
                                    "color":"#8cd5f1"
                                }
                            }
                        }
                    ]
                ]
            }
        },
        {
            "symbolSize":1,
            "color":"#fff",
            "data":[
                [
                    10,
                    10
                ]
            ],
            "type":"scatter"
        }
    ]
}

最后就是这个样子,其实代码写的有点多,没必要这么多,但是我懒得删除了,需要的话自己根据经验删除修改就行:

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中使用echarts,你可以通过全局引入或按需引入的方式来使用echarts库。全局引入的方法是在main.js文件中引入echarts,并将其挂载在Vue的原型上,以便在整个项目中可以直接通过this.$echarts来使用echarts库。具体代码如下: ```javascript // main.js import echarts from "echarts"; Vue.prototype.$echarts = echarts; ``` 这样,在Vue的组件中就可以通过this.$echarts来调用echarts库的各种功能了。比如你可以在组件的mounted钩子函数中使用this.$echarts来初始化一个echarts实例,并使用其提供的API来绘制图表。 另外,如果你只需要使用一部分echarts功能,你也可以按需引入echarts的模块。具体的使用方法可以参考echarts官方文档或者其他相关资源。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Vue使用echarts(完整版,解决各种报错)](https://blog.csdn.net/geidongdong/article/details/122561517)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [在vue中使用Echart图表。小白篇](https://blog.csdn.net/qq_43153895/article/details/108214450)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值