Browse Source

正态

master
songguoqiang 11 months ago
parent
commit
87619586a3
  1. 6
      src/components/Detail/src/TemplateDetails.vue
  2. 282
      src/views/tjanalysis/zlanalysis/components/ztfbview.vue
  3. 8
      src/views/tjanalysis/zlanalysis/index.vue

6
src/components/Detail/src/TemplateDetails.vue

@ -293,8 +293,12 @@ const rowRef = ref()
const openForm = (type: string, row?: any) => {
if(type=='update'){
console.log(row)
TemplateItemDetails.allSchemas.formSchema.forEach(item=>{
// if(item.field=='type'){
// debugger
// item.componentProps.disabled=true;
// }
if(item.component == 'UploadFile'){
if(row[item.field]){
item.componentProps.modelValue = [{

282
src/views/tjanalysis/zlanalysis/components/ztfbview.vue

@ -5,16 +5,18 @@
</template>
<script lang="ts" setup>
import * as echarts from 'echarts'
import { number } from 'vue-types'
import * as math from './ztmath'
const dialogVisible = ref(false) //
/** 打开弹窗 */
const open = (_data , _lowLimit , _upLimit) => {
if(_data.length<=0){
const open = (ztData) => {
if(ztData.length<=0){
dialogVisible.value = false
}else{
initData(_data , _lowLimit , _upLimit)
console.info(JSON.stringify(ztData))
initData(ztData)
dialogVisible.value = true
}
}
@ -30,26 +32,52 @@ function func(x, u, a) {
);
}
const initData = async (data , xMin , xMax) => {
var mean = math.mean(data) // math.js
var stdev = math.std(data) //
var threeSigUp = mean + 3 * stdev
var threeSigLow = mean - 3 * stdev
function pdf(x, mu, sigma) {
return (1 / (Math.sqrt(2 * Math.PI) * sigma)) * Math.exp(-0.5 * ((x - mu) / sigma) ** 2);
}
const initData = async (ztData) => {
let data = ztData.ztMap.datas;
let xMax = ztData.ztMap.upLimit;
let xMin = ztData.ztMap.downLimit;
let sigma = ztData.ztMap.sigma;
let stdev = ztData.ztMap.stdev;
let avgX = ztData.ztMap.avgX;
let max = ztData.ztMap.max;//线
//let mean = math.mean(data) // math.js
var threeSigUp = Number(avgX) + (3 * sigma)
var threeSigLow = Number(avgX) - (3 * sigma)
const resNum = await getResNum(data)
const xArr = await getXArr(resNum)
const fArr = await getFArr(xArr , resNum)
const yArr = await getYArr(xMax , xMin , mean , stdev)
var threeSigUp1 = Number(avgX) + (2 * sigma)
var threeSigLow1 = Number(avgX) - (2 * sigma)
setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp)
}
var threeSigUp2 = Number(avgX) + (1 * sigma)
var threeSigLow2 = Number(avgX) - (1 * sigma)
let maxX = xMax;
if(Number(threeSigUp)>Number(xMax)){
maxX = threeSigUp;
}
const resNum = await getResNum(data)//
const xArr = await getXArr(resNum)//X
//const fArr = await getFArr(xArr , resNum)//Y
let fArr = ztData.ztMap.fArr
let pingjun = func(avgX, avgX, stdev);//
const yArr = await getYArr(maxX,xMax , xMin , avgX , stdev,pingjun,max)
console.info("resNum",JSON.stringify(resNum));
console.info("xArr",JSON.stringify(xArr));
console.info("fArr",JSON.stringify(fArr));
console.info("yArr",JSON.stringify(yArr));
setEchartData(xMin , xMax , yArr , fArr,threeSigLow , threeSigUp,threeSigUp1,threeSigLow1,threeSigUp2,threeSigLow2,avgX)
}
//
const getResNum = async (datas) => {
var resNum = {}
const dataSec = datas.sort((a, b) => {
const dataSec = datas.sort((a, b) => {//
return a - b;
})
console.info("dataSec",JSON.stringify(dataSec));
for (var m = 0; m < dataSec.length; m++) {
var key = parseFloat(dataSec[m]);
if (parseFloat(key + '') === 0) continue;
@ -59,7 +87,7 @@ const getResNum = async (datas) => {
return resNum
}
//
const getXArr = async (resNum) => {
var xArr = [] //
for (var k in resNum) {
@ -70,30 +98,61 @@ const getXArr = async (resNum) => {
})
return xArr
}
//[[0.99, 109]]
const getFArr = async (xArr , resNum) => {
var fArr = [] //
//x
for (var i = 0; i < xArr.length; i++) {
var xNy = [xArr[i], resNum[xArr[i]]]
//var xNy = resNum[xArr[i]]
fArr.push(xNy)
}
return fArr
}
const getYArr = async (xMax , xMin , mean , stdev) => {
const getYArr = async (maxX,xMax , xMin , mean , stdev,pingjun,max:number) => {
debugger
var yArr = [] //
let jj = 0.01;//
let jian = maxX-xMin;
//x
if(jian>0){
jj = 0.01;
}
else if(jian>=2){
jj = 0.02
}else if(jian>=5){
jj = 0.05
}else if(jian>=10){
jj = 0.1
}else if(jian>=20){
jj = 0.5
}else{
jj = 1
}
let beishu =Math.floor((max+25)/(Number(pingjun)));//线+42/ 线
var distance = xMax - xMin //线
for (var j = xMin + distance / 4; j < xMax - distance / 4; j += 0.01) {
var xy = [j, func(j, mean, stdev)]
for (var j = xMin + distance / 4; j < maxX-distance / 4; j += jj) {
//for (var j = xMin + distance / 4; j < xMax-distance / 4; j += 0.01) {
var xy = [j, func(j, mean, stdev)*beishu]
//var xy = [j, pdf(j, mean, stdev)]
yArr.push(xy)
}
return yArr
}
// echarts
function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp,threeSigUp1,threeSigLow1,threeSigUp2,threeSigLow2,avgX) {
let avgXs = avgX;
let maxX = xMax;
let minX = xMin;
if(Number(threeSigUp)>Number(maxX)){
maxX = threeSigUp;
}
if(Number(threeSigLow)<Number(minX)){
minX = threeSigLow;
}
var dom = document.getElementById("ztEcharts")
var myChart = echarts.init(dom, null, {
renderer: "canvas",
@ -108,19 +167,19 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
}
},
legend: {
orient: "vertical",
// orient: "vertical",
x: "right",
y: "top",
top: "5px",
data: ["频数", "正态分布"],
data: [ "正态分布","频数"],
textStyle: {
color: "rgba(255,255,255,1)",
color: "green",
fontSize: "12"
}
},
grid: {
left: "2%",
top: "18px",
top: "45px",
right: "2%",
bottom: "2%",
containLabel: true
@ -128,8 +187,8 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
xAxis: [
{
type: "value",
min: xMin,
max: xMax,
min: minX.toFixed(2),
max: maxX.toFixed(2),
axisLabel: {
textStyle: {
color: '#000000',
@ -150,7 +209,7 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
yAxis: [
{
type: "value", //
name: "正态曲线",
name: "正态分布",
position: "right",
axisTick: { show: true },
axisLine: {
@ -227,7 +286,7 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
markLine: {
symbol: ["none"],
lineStyle: {
type: "dotted",
type: "solid",
color: "yellow"
},
itemStyle: {
@ -242,30 +301,72 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
},
data: [
{
name: "3σ",
name: "3S",
xAxis: threeSigLow.toFixed(2),
label: {
show: true,
formatter: ""
formatter: "-3S"
}
},
{
name: "3σ",
name: "3S",
xAxis: threeSigUp.toFixed(2),
label: {
show: true,
formatter: "3σ"
formatter: "+3S"
}
},
{
name: "2S",
xAxis: threeSigLow1.toFixed(2),
label: {
show: true,
formatter: "-2S"
}
},
{
name: "2S",
xAxis: threeSigUp1.toFixed(2),
label: {
show: true,
formatter: "+2S"
}
},
{
name: "1S",
xAxis: threeSigLow2.toFixed(2),
label: {
show: true,
formatter: "-1S"
}
},
{
name: "1S",
xAxis: threeSigUp2.toFixed(2),
label: {
show: true,
formatter: "+1S"
}
}
,
{
name: "1S",
xAxis: avgXs,
label: {
show: true,
formatter: "平均:"+avgXs
}
}
]
}
},
{
name: "频数",
type: "bar",
yAxisIndex: 1,
yAxisIndex: 0,
xAxisIndex: 0,
barWidth: 8,
barWidth: 24,
barGap: 1,
symbol: "solid",
symbolSize: 5,
@ -279,7 +380,7 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
},
data: fArr,
markLine: {
symbol: ["none"],
symbol: ["circle","arrow"],
lineStyle: {
type: "dotted",
color: "red"
@ -300,7 +401,7 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
xAxis: xMin.toFixed(2),
label: {
show: true,
formatter: "Low"
formatter: '下限'+xMin.toFixed(2)
}
},
{
@ -308,7 +409,7 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
xAxis: xMax.toFixed(2),
label: {
show: true,
formatter: "High"
formatter: '上限:'+xMax.toFixed(2)
}
}
]
@ -327,6 +428,109 @@ function setEchartData(xMin , xMax , yArr , fArr , threeSigLow , threeSigUp) {
}
}
// echarts
function setEchartData1(xMin , xMax , yArr , fArr,xArr , threeSigLow , threeSigUp) {
var dom = document.getElementById("ztEcharts")
var myChart = echarts.init(dom, null, {
renderer: "canvas",
useDirtyRect: false
})
var option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
crossStyle: {
color: '#999'
}
}
},
toolbox: {
feature: {
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
legend: {
data: ['Evaporation', 'Precipitation', 'Temperature']
},
xAxis: [
{
type: 'category',
data: xArr,
axisPointer: {
type: 'shadow'
}
}
],
yAxis: [
{
type: 'value',
name: 'Precipitation',
min: 0,
max: 250,
interval: 50,
axisLabel: {
formatter: '{value} ml'
}
},
{
type: 'value',
name: 'Temperature',
min: 0,
max: 25,
interval: 5,
axisLabel: {
formatter: '{value} °C'
}
}
],
series: [
{
name: 'Evaporation',
type: 'bar',
tooltip: {
valueFormatter: function (value) {
return value + ' ml';
}
},
data: fArr
},
{
name: 'Temperature',
type: 'line',
yAxisIndex: 1,
tooltip: {
valueFormatter: function (value) {
return value + ' °C';
}
},
data: yArr
}
]
};
if (option && typeof option === "object") {
myChart.setOption(option)
}
window.onresize = function () {
//
myChart.resize()
}
}
onMounted(() => {
// const script = document.createElement('script');
// script.setAttribute('src', math);

8
src/views/tjanalysis/zlanalysis/index.vue

@ -7,6 +7,8 @@
class="demo-form-inline"
style="margin-bottom: -17px"
label-width="100px"
labelPosition="left"
>
<el-form-item label="项目" style="width: calc(20% - 32px)">
<el-select
@ -383,9 +385,9 @@ function setChart2(rangeData) {
}
function setChart3(ztData) {
if (ztData != null) {
myEcharts3Ref.value.open(ztData.datas , ztData.downLimit , ztData.upLimit)
myEcharts3Ref.value.open(ztData)
}else{
myEcharts3Ref.value.open([] , null , null)
myEcharts3Ref.value.open([])
}
}
function setChart4(ybData) {
@ -554,7 +556,7 @@ const changTabIndex = async (tIndexV) => {
ec1Loading.value = false
ec2Loading.value = false
} else if (tIndexV == 1) {
setChart3(dvDatas.ztMap)
setChart3(dvDatas)
ec3Loading.value = false
} else if (tIndexV == 2) {
setChart4(dvDatas.ybMap)

Loading…
Cancel
Save