ECharts绘制正态分布曲线的标记线和标记区域

<template>
  <div id="main"></div>
</template>

<script setup>
import { onMounted } from "vue";
import * as echarts from "echarts";
let data={
  x:[
    -3,-2.6842105263157894,-2.3684210526315788, 
    -2.052631578947368,-1.7368421052631575,-1.421052631578947,-1.1052631578947363, 
    -0.7894736842105258,-0.47368421052631526,-0.15789473684210475,
    0.15789473684210575,0.47368421052631626,0.7894736842105268,
    1.1052631578947372,1.4210526315789478,1.7368421052631584,
    2.052631578947369, 2.3684210526315796,2.6842105263157903],
  y:[
    0.0044318484119380075, 0.010873446008403894,   0.02414573124668899,
    0.04852933916733306,   0.08827937454560608, 0.14534663197630093,
    0.21659157163219764,   0.292125176410827, 0.3566048764304543,
    0.394000182232257,   0.39400018223225697, 0.3566048764304541,
    0.29212517641082686,  0.21659157163219742, 0.14534663197630074,
    0.08827937454560594,   0.04852933916733297, 0.024145731246688947,
    0.010873446008403865],
    nominal:0,
    lower:-1.0,
    upper:1.0
};
let arr= [];
for(let i=0;i<data.x.length;i++){
  arr.push([data.x[i],data.y[i]])
}
console.log('arr',arr);

onMounted(() => {
  // 1.基于准备好的dom,初始化echarts实例
  var myChart = echarts.init(document.getElementById("main"));
  // 2.指定图表的配置项和数据, Echarts 图的配置
  var option = {
    title: {
        text: '正态分布曲线',
        left: 'center'
    },
    xAxis: {
        type: 'value',
        splitLine:{
          show:false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
          show: false
        },
        axisLabel: {
          show: false
        },
        splitLine: {
          show: false
        },
        axisTick:{
          show: false
        }
    },
    series: [{
        type: 'line',
        data: arr,
        markLine: {
            symbol: ['none', 'none'],
            data: [
                { xAxis: data.nominal, name: 'Nominal', label: { formatter: 'Nominal' },
                  lineStyle:{
                    color:'blue'
                  } },
                { xAxis: data.lower, name: 'Lower', label: { formatter: 'Lower' } , lineStyle:{
                    color:'green'
                  }},
                { xAxis: data.upper, name: 'Upper', label: { formatter: 'Upper' } ,
                lineStyle:{
                    color:'green'
                  }}
            ]
        },
        markArea: {
          itemStyle: {
            color: 'lightGreen'
          },
          data: [
            [{
              xAxis: -2,
              yAxis: 0.1
            }, {
              xAxis: 2,
              yAxis: 0.2
            }]
          ]
    },
    }]
  }
  // 3.使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
  window.addEventListener("resize", () => {
    myChart.resize()
  })
});
</script>

<style>
#main {
  width: 600px;
  height: 400px;
}
</style>

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值