echarts散点图(象限图)设置不同的颜色

如图所示:

java 复制代码
<template>
    <div ref="sdtcmijy" :style="{height:scrollerHeight}"></div>
</template>
<script>
import {getXxt} from './../requestAPI.js'

export default {
    data(){
        return {
            params:{},
            seriesData:[],
            xmin:0,
            scrollerHeight: document.body.clientHeight - 170 + "px",
        }
    },
    methods:{
        reset(){
            this.seriesData=[];
        },
        init(params){
            this.reset();
            this.params=params;
            this.search();
        },  
        search(){
            getXxt(this.params).then(res=>{
                if(res.status===200){
                    let data=res.data.list.list;
                    this.xmin=res.data.xmin;
                    console.log(this.xmin)
                    if(data.length>0){
                        data.forEach(item => {
                            let obj=[item.fcmi,item.fybjy];
                            let val = { name: item.name, value: obj };
                            this.seriesData.push(val);
                        });
                        this.seriesData = this.seriesData.map(d => ({
                            ...d,
                            itemStyle: {
                               
                                color: this.getAreaPointColor(d.value)
                            }
                        }))
                       
                    }
                     this.initCharts();
                    
                }
            });
        },
        getAreaPointColor (value) {
            console.log(value)
            let [x, y] = value
            if(x >= this.xmin && y >= 0){
                return '#32CD32	'
            }else if(x < this.xmin && y >= 0){
                
                return '#3583FF'
            }else if(x < this.xmin && y < 0){
                return '#FF0000	'
            }else if(x >= this.xmin && y < 0){
                return '#FF7F24'
            }
            
        },
        initCharts(){
            let that=this;
            let chartDom = this.$refs.sdtcmijy;
            let myChart = this.$echarts.init(chartDom);
            let option;

            option = {
                toolbox: {
                feature: {
                    saveAsImage: {},
                },
                },
                tooltip: {
                    position: "top",
                    formatter: "名称: {b}<br />" + "数值" + ": {c}",
                    },
            xAxis: {
                name:"x轴",
                type:'value',
                scale: true,
                min: function (value) {
                    if (Math.abs(value.min) > Math.abs(value.max)) {
                    return Math.floor(-Math.abs(value.min));
                    } else {
                    return Math.floor(-value.max);
                    }
                },
                max:function (value) {
                    if (Math.abs(value.min) > Math.abs(value.max)) {
                    return Math.ceil((that.xmin-(Math.floor(-Math.abs(value.min))))-(Math.ceil(Math.abs(value.min))-that.xmin)+Math.abs(value.min))
                    ;
                    } else {
                    return Math.ceil((that.xmin-(Math.floor(-value.max)))-(Math.ceil(value.max)-that.xmin)+value.max)
                    ;
                    }
                },
            },
            yAxis: {
                name:"y轴",
                type:'value',
                min: function (value) {
                    if (Math.abs(value.min) > Math.abs(value.max)) {
                    return Math.floor(-Math.abs(value.min));
                    } else {
                    return Math.floor(-value.max);
                    }
                },
                max: function (value) {
                    if (Math.abs(value.min) > Math.abs(value.max)) {
                    return Math.ceil(Math.abs(value.min));
                    } else {
                    return Math.ceil(value.max);
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#E8E8E8', // 设置坐标轴颜色
                    }
                },
                axisLabel:{
                    color:'#000',
                    
                },
                nameTextStyle:{
                    color:'#000',
                }
            },
            dataZoom: [
          {
            //滚动条
            bottom: 10,
            id: "dataZoomX",
            type: "slider",
            xAxisIndex: [0],
            filterMode: "filter",
            start: 0,
            end: 100,
          },
          {
            //滚动条
            left: 0,
            id: "dataZoomY",
            type: "slider",
            yAxisIndex: [0],
            filterMode: "filter",
            start: 0,
            end: 100,
          },
        ],
            series: [
                {
                name: "名称",
                symbolSize: 20,
                data: this.seriesData,
                type: 'scatter',
                markLine: {
                    label:{
                        show:true,
                        position:'insideStartTop'
                    },
                    symbol:[],
                    lineStyle: {
                            color: '#000',
                            type: "solid" 
                        },
                data: [
                            {
                                
                                xAxis: this.xmin
                            }
                        ]
                }

                }
            ]
            };

            option && myChart.setOption(option);
        }
    }
}
</script>
<style scoped>

</style>
相关推荐
代码小库几秒前
【课程作业必备】Web开发技术HTML静态网站模板 - 校园动漫社团主题完整源码
前端·html
VT.馒头几秒前
【力扣】2722. 根据 ID 合并两个数组
javascript·算法·leetcode·职场和发展·typescript
珹洺7 分钟前
Bootstrap-HTML(二)深入探索容器,网格系统和排版
前端·css·bootstrap·html·dubbo
BillKu7 分钟前
VS Code HTML CSS Support 插件详解
前端·css·html
xixixin_13 分钟前
【React】中 Body 类限定法:优雅覆盖挂载到 body 的组件样式
前端·javascript·react.js
换日线°19 分钟前
NFC标签打开微信小程序
前端·微信小程序
张3蜂2 小时前
Python 四大 Web 框架对比解析:FastAPI、Django、Flask 与 Tornado
前端·python·fastapi
南风知我意9572 小时前
【前端面试5】手写Function原型方法
前端·面试·职场和发展
qq_12498707532 小时前
基于Java Web的城市花园小区维修管理系统的设计与实现(源码+论文+部署+安装)
java·开发语言·前端·spring boot·spring·毕业设计·计算机毕业设计
摘星编程2 小时前
用React Native开发OpenHarmony应用:Image网络图片加载
javascript·react native·react.js