Files
2-BeiqiFutian-MES_Manage/App_code/drawchart/CalculateData.cs
2026-05-29 13:44:19 +08:00

144 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
/// <summary>
///CalculateData 的摘要说明
/// </summary>
public class CalculateData
{
public CalculateData()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 观测值最大值
/// </summary>
/// <param name="Xn">子组观测值</param>
/// <returns></returns>
static private double Max(double[] Xn)
{
double temp;
temp = Xn[0];
for (int i = 0; i < Xn.Length; i++)
{
temp = (Xn[i] > temp) ? Xn[i] : temp;
}
return temp;
}
/// <summary>
/// 观测值最小值
/// </summary>
/// <param name="Xn">子组观测值</param>
/// <returns></returns>
static private double Min(double[] Xn)
{
double temp;
temp = Xn[0];
for (int i = 0; i < Xn.Length; i++)
{
temp = (Xn[i] < temp) ? Xn[i] : temp;
}
return temp;
}
/// <summary>
/// 计算X在区间[ValueDownValueUp]的数量
/// </summary>
/// <param name="X"></param>
/// <param name="GroupCount"></param>
/// <param name="ValueDown"></param>
/// <param name="ValueUp"></param>
/// <param name="Yk"></param>
static private void SumRang(double[] X, int GroupCount, double[] ValueDown, double[] ValueUp, out double[] Yk, out double[] YkCount)
{
int temp = 0;
//总数量
int allCount = 0;
Yk = new double[GroupCount];
YkCount = new double[GroupCount];
for (int j = 0; j < GroupCount - 1; j++)
{
temp = 0;
for (int i = 0; i < X.Length; i++)
{
if (X[i] >= ValueDown[j] & X[i] < ValueUp[j])
{
temp = temp + 1;
allCount++;
}
}
Yk[j] = temp;
}
for (int i = 0; i < X.Length; i++)
{
if (X[i] >= ValueDown[GroupCount - 1] & X[i] <= ValueUp[GroupCount - 1])
{
temp = temp + 1;
allCount++;
}
}
Yk[GroupCount - 1] = temp;
for (int i = 0; i < Yk.Length; i++)
{
YkCount[i] = Yk[i];
Yk[i] = Yk[i] / (double)allCount * 100;
}
}
public static void DataPareto(double[] Data,int GroupCount)
{
Spc_Data_Pareto m_Spc_Data_Pareto = new Spc_Data_Pareto();
//数组最大值
double minValue = Min(Data);
//数组最小值
double maxValue = Max(Data);
//X轴刻度
double XSpan = (maxValue - minValue) / GroupCount;
//X轴下刻度线
double[] XSpanDown = new double[GroupCount];
//X轴上刻度线
double[] XSpanUp = new double[GroupCount];
double[] Yk=new double[GroupCount];
XSpanDown[0] = minValue;
XSpanUp[0] = minValue + XSpan;
for (int i = 1; i < GroupCount; i++)
{
XSpanDown[i] = minValue + i * XSpan;
XSpanUp[i] = minValue + (i + 1) * XSpan;
}
//数据在区间数组的数量
SumRang(Data, GroupCount, XSpanDown, XSpanUp, out Yk, out m_Spc_Data_Pareto.YCount);
for (int i = 0; i < GroupCount; i++)
{
if (i == 0)
{
m_Spc_Data_Pareto.AxisX[i] = minValue + XSpan / 2;
}
else
{
m_Spc_Data_Pareto.AxisX[i] = minValue + XSpan;
}
}
}
}
/// <summary>
/// 排列图数据
/// </summary>
public class Spc_Data_Pareto
{
//X轴数据
public double[] AxisX;
//所有数据在X轴各范围内的数量
public double[] YCount;
}