开发笔记,有缘人,阅
<template>
<header>
<body>
<div id="two">
<a> {{msg}} </a>
</div>
<div class="pass">
<div class="xinzeng1">5</div>
<div class="xinzeng4">
<div class="text">
<div id="myChart2" :style="{width: '100%', height: '100%'}"></div>
</div>
<div class="text2">
<p>sdfsfdsdfsdfsdfsdfsdffd </p>
</div>
<button @click="CalcBatCPK(1.3045,10.2615,24,7,15,text,19.456,8.36)">CPK 测试</button>
<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:#6FB7B7;"></span>
</div>
</div>
<div id="yu">
<p>sdfsfdsdfsdfsdfsdfsdffd </p>
<h1> dfsdfsdf5555 </h1>
<a> {{msg}} </a>
</div>
</body>
</header>
</template>
<style scoped>
body{
/*background-image: url("./assets/12.jpg");*/
background-repeat:no-repeat;
width:1208px;
height: 900px;
}
.pass{
margin: 0;
padding: 0;
width:99%;
height: 90%;
position: absolute;
}
.xinzeng1{
width:72%;
height: 55%;
float:left;
background:rgb(230, 245, 188);
}
.xinzeng4{
width:28%;
height: 55%;
float:left;
background:rgb(255, 255, 205);
}
.text{
width:100%;
height: 90%;
border-radius:15px
}
.text2{
width:100%;
height: 10%;
border-radius:15px
}
</style>
<script>
export default {
name: 'two',
data () {
return {
msg: 'I am twocccccccccccccccccccccccccccccccccccccccccccccc',
BarX:[3,2,5,6,15,17,21,26,42,37,45,44,53,33,35,27,25,17,17,7,12,5,3,1,2],
LineX:[0.0195362866170644,0.0329676330209117,0.0528824759946282,0.080633230425571,0.116867728390018,0.161010207774185,0.210858194283367,0.262485803952267,0.310598548927497,0.34935847986543,0.373526501931662,0.379620639910312,0.366738477627864,0.336776208697881,0.293971070499289,0.243919234823682,0.192382590687355,0.144232706593539,0.102787428835202,0.069629698804273,0.0448360448847198,0.0274434267282686,0.0159671588832651,0.00883070180317537,0.00464238396251034],
RangX:[7.39794436659249,7.6343913412363,7.87083831588011,8.10728529052393,8.34373226516774,8.58017923981155,8.81662621445537,9.05307318909918,9.289520163743,9.52596713838681,9.76241411303062,9.99886108767444,10.2353080623182,10.4717550369621,10.7082020116059,10.9446489862497,11.1810959608935,11.4175429355373,11.6539899101811,11.8904368848249,12.1268838594688,12.3633308341126,12.5997778087564,12.8362247834002,13.072671758044],
XX:["sfsdf","dfgdf","dfgdf","dfgdf","dfgdf"],
uu:"22222",
LSLine:"",
USLine:"",
Min:"",
Max:"",
DtRange:[],
text:"2021/03/12 08:00:00$abcefg1639800$19.456@#2021/03/12 08:01:00 $abcefg1519685$12.491@#2021/03/12 08:02:00 $abcefg9230974$9.751@#2021/03/12 08:03:00 $abcefg1221880$10.461@#2021/03/12 08:04:00 $abcefg6320151$11.066@#2021/03/12 08:05:00 $abcefg6973407$10.142@#2021/03/12 08:06:00 $abcefg8085600$9.47@#2021/03/12 08:07:00 $abcefg6559525$8.365@#2021/03/12 08:08:00 $abcefg4086197$11.487@#2021/03/12 08:09:00 $abcefg7564426$9.394@#2021/03/12 08:10:00 $abcefg7573168$9.682@#2021/03/12 08:11:00 $abcefg7594452$11.186@#2021/03/12 08:12:00 $abcefg5448205$8.519@#2021/03/12 08:13:00 $abcefg8009836$8.668@#2021/03/12 08:14:00 $abcefg2723945$8.918@#2021/03/12 08:15:00 $abcefg6584766$11.58@#2021/03/12 08:16:00 $abcefg6977861$10.786@#2021/03/12 08:17:00 $abcefg7046163$8.498@#2021/03/12 08:18:00 $abcefg8276548$11.702@#2021/03/12 08:19:00 $abcefg2607741$12.967@#2021/03/12 08:20:00 $abcefg1177848$10.185@#2021/03/12 08:21:00 $abcefg4520452$9.185@#2021/03/12 08:22:00 $abcefg2855074$11.481@#2021/03/12 08:23:00 $abcefg4218669$10.845"
}
},
methods:{
drawLine2(){
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById('myChart2'));
const labelOption = {
show: true,
position: 'insideRight'
}
let uu=this.XX;
// 绘制图表
myChart.setOption({
//title: { text: '在Vue中使用echarts' },
tooltip: {
/*/trigger: 'item',
formatter: function(a){
console.log(a);
return "<div>"+a.marker+"</div>";
//"{a} <br/>{b} : {c} ({d}%)"
}*/
},
xAxis:[
{
data: this.RangX,
},
{ //第二条 X 轴,放置规格上下限
max:this.Max,
min:this.Min,
show:false,
// splitLine:{
// show:false
// },
// axisLine:{ //x轴坐标轴,false为隐藏,true为显示
// show:false
// },
// axisLabel:{ //x轴坐标轴,false为隐藏,true为显示
// show:false
// },
}
],
//color: ['#00FF00', '#FF0000'],
grid:{
left: '5%', // 与容器左侧的距离
right: '5%', // 与容器右侧的距离
top: '5%', // 与容器顶部的距离
bottom: '5%', // 与容器底部的距离
},
legend: {
left: 'right',
top:'top',
data: ['IR', 'SK']
},
yAxis: [
{
show:false,
// position: 'left',
// splitLine:{
// show:false
// },
// axisLine: {onZero: false,show:false},
// axisLabel:{show:false},//x轴坐标轴,false为隐藏,true为显示
},
{
show:false,
// position: 'right',
// splitLine:{
// show:false
// },
// axisLine: {onZero: false,},
// axisLabel:{show:false},//x轴坐标轴,false为隐藏,true为显示
}
],
//barGap: '10%',
series: [
{
//name: "IR",
type: 'bar',
barCategoryGap:0.3,
color:'#6FB7B7',
data: this.BarX,
yAxisIndex:0,
},
{
name: this.Txt,
type: 'line',
smooth:true, //关键点,为true是不支持虚线,实线就用true
symbol: "circle", //取消关键点
symbolSize:2,
yAxisIndex:1,
//showSymbol: false,
itemStyle:{
normal:{
color:'#6C3365' ,
lineStyle:{
width:2,
type:'solid', //'dotted'虚线 'solid'实线
color:'#6C3365'
}
}
},
data: this.LineX,
},
{
name:'规格线',
type:'line',
xAxisIndex:1,
markLine : {
symbol:'none',
lineStyle: {
normal: {
//type: 'dotted',
color:'#6C3365' ,
}
},
data : [
{
name:'LSL',
label:{
show:true,
position:'end',
formatter: '{b}: {c}'
},
xAxis:this.LSLine,
},
{
name:'USL',
label:{
show:true,
position:'end',
formatter: '{b}: {c}'
},
xAxis:this.USLine,
},
]
}
}
]
});
},
CalcBatCPK(sigm,mean,QTY,LSL,USL,DataX,Max,Min){//计算直方图的数据
this.BarX=[];
this.LineX=[];
this.RangX=[];
this.DtRange=[];
/* 组距的算法:
组距=(6*sigma)/sqrt(QTY)
*/
var Rangx=0;
if(Math.sqrt(parseInt(QTY))<12){
Rangx=(5* parseFloat(sigm))/12;
}else{
Rangx = (5* parseFloat(sigm))/Math.sqrt(parseInt(QTY));
}
// 最高支持 0.001的区分精度
var roundupX=parseInt(0);
if(Rangx<0.0001){
Rangx= Rangx.toFixed(5);
roundupX=5;
}else if(Rangx<0.001){
Rangx= Rangx.toFixed(4);
roundupX=4;
}else if(Rangx<0.01){
Rangx= Rangx.toFixed(3);
roundupX=3;
}else if(Rangx<0.1){
Rangx= Rangx.toFixed(2);
roundupX=2;
}else if(Rangx<10){
Rangx= Rangx.toFixed(1);
roundupX=1;
}else{
Rangx= Rangx.toFixed(0);
}
//*********************以上为组距的算法 */
var DtLSL;
var DtUSL;
if(parseFloat(LSL)<parseFloat(Min)){
DtLSL = parseFloat(LSL)-parseFloat(Rangx);
}else{
DtLSL = parseFloat(Min)-parseFloat(Rangx);
}
if(parseFloat(USL)>parseFloat(Max)){
DtUSL = parseFloat(USL)+parseFloat(Rangx);
}else{
DtUSL = parseFloat(Max)+parseFloat(Rangx);
}
// this.USLine = USL;
// this.LSLine = LSL;
this.Max = DtUSL;
this.Min = DtLSL;
//console.log(DtLSL +"----"+ DtUSL);
while(DtLSL<DtUSL){
this.DtRange.push({"Rank":DtLSL,"bar":0,"Line":""});
DtLSL=parseFloat(DtLSL)+parseFloat(Rangx);
DtLSL=parseFloat(DtLSL.toFixed(roundupX));//避免出现0.99999999999999999的问题
console.log(DtLSL);
}
var DataAll = DataX.split("@#");
var DataItm = [];
DataAll.forEach(ele => {
DataItm = ele.split("$");// 第三个字符里放有计算CPK 的值
this.FixRankData(DataItm[2]);
});
this.DtRange.forEach(ele => {
ele.Line = this.FixRankLine(ele.Rank,mean,sigm);
});
this.DtRange.forEach(ele => {
this.BarX.push(ele.bar);
this.LineX.push(ele.Line);
this.RangX.push(ele.Rank);
});
this.USLine = parseFloat(USL);
this.LSLine = parseFloat(LSL);
this.drawLine2();
console.log(this.DtRange);
},
FixRankLine(x,mean,sigma){//计算直方图的正态曲线
/* 正态分布线算法如下:
f(x)= 1/(sigma*根号下2 Pi) * 自然常数E 的次方,次方数: -(x-mean)^2/(2*sigma^2)
*/
var D2PI=2.506628274631; // 根号下2* pi
var EXPx= 2.71828182845905; //自然常数E
var sigma2Pi = 1/(parseFloat(sigma)*D2PI); // 1/(sigma*根号下2 Pi)
var Ecifang = -Math.pow((parseFloat(x)-parseFloat(mean)),2)/(2*Math.pow(parseFloat(sigma),2)); //自然常数E 的次数
return sigma2Pi*(Math.pow(EXPx,Ecifang));
},
FixRankData(x){//计算直方图每个柱子的高度
var Ldata="";
this.DtRange.forEach(ele => {
if(x >= parseFloat(Ldata) && x < parseFloat(ele.Rank)){
ele.bar = parseInt(ele.bar)+1;
}
Ldata = ele.Rank;
});
}
},
mounted(){
this.drawLine2();
}
}
</script>