📄 frmhistoryview.cs
字号:
{
redNo = i.ToString();
}
cbRedNo.Items.Add(redNo);
}
cbRedNo.SelectedIndex = 0;
}
#endregion
private void btnStatCur_Click(object sender, EventArgs e)
{
int statNum; //统计期数
int redBallNo; //红球号
//判断数据的合法性
if (mtbStatNum.Text.Trim() == string.Empty)
{
MessageBox.Show("请输入统计期数!");
mtbStatNum.Focus();
return;
}
else
{
statNum = Convert.ToInt32(mtbStatNum.Text.Trim().ToString());
}
redBallNo = cbRedNo.SelectedIndex;
if (redBallNo < 1 || redBallNo > 33)
{
redBallNo = 1;
}
ShowChartPanl("btnStatCur");
ShowChart(redBallNo, statNum);
ShowStatInfo(statResult);
}
#region//显示图表
/// <summary>
/// 显示统计图表
/// </summary>
/// <param name="redBallNo">要统计红球号码</param>
/// <param name="statNum">要统计的期数</param>
private void ShowChart(int redBallNo, int statNum)
{
//转换数组
ArrayList tempArray = new ArrayList();
double[] yValue; //y值数组
int Summation; //总和
string [][] curRedBallData ; //当前红球号的统计数据
//得到统计数据
tempArray = redBall.GetRedFrequency(statNum, redBallNo);
if (tempArray.Count == 0)
{
MessageBox.Show("没有查到数据!");
return;
}
curRedBallData = new string[tempArray.Count][];
tempArray.CopyTo(curRedBallData);
//把string数组转换成double数组,只有间隔期数,没有序号
yValue = new double[curRedBallData.Length];
for (int i = 0; i < yValue.Length; i++)
{
yValue[yValue.Length - i - 1] = Convert.ToDouble(curRedBallData[i][1].ToString());
}
//初始化面板
plChart.Controls.Clear();
ZedGraph.ZedGraphControl zgMain = new ZedGraph.ZedGraphControl();
zgMain.Dock = System.Windows.Forms.DockStyle.Fill;
plChart.Controls.Add(zgMain);
GraphPane myPane = zgMain.GraphPane;
myPane.Title.Text = "红球历史数据分布图";
myPane.XAxis.Title.Text = "出现次数";
myPane.YAxis.Title.Text = "间隔期数";
// Generate a red bar with "Curve 1" in the legend
CurveItem myCurve = myPane.AddBar("红球" + redBallNo.ToString(), null, yValue, Color.Blue);
// Draw the X tics between the labels instead of at the labels
myPane.XAxis.MajorTic.IsBetweenLabels = true;
// Set the XAxis to the ordinal type
myPane.XAxis.Type = AxisType.Ordinal;
// Shift the text items up by 5 user scale units above the bars
const float shift = 0;
for (int i = 0; i < yValue.Length; i++)
{
// format the label string to have 1 decimal place
string lab = yValue[i].ToString("F1");
// create the text item (assumes the x axis is ordinal or text)
// for negative bars, the label appears just above the zero value
TextObj text = new TextObj(lab, (float)(i + 1), (float)(yValue[i] < 0 ? 0.0 : yValue[i]) + shift);
// tell Zedgraph to use user scale units for locating the TextObj
text.Location.CoordinateFrame = CoordType.AxisXYScale;
// AlignH the left-center of the text to the specified point
text.Location.AlignH = AlignH.Left;
text.Location.AlignV = AlignV.Center;
text.FontSpec.Border.IsVisible = false;
text.FontSpec.Fill.IsVisible = false;
// rotate the text 90 degrees
text.FontSpec.Angle = 90;
// add the TextObj to the list
myPane.GraphObjList.Add(text);
}
// Indicate that the bars are overlay type, which are drawn on top of eachother
myPane.BarSettings.Type = BarType.Overlay;
// Fill the axis background with a color gradientC:\Documents and Settings\champioj\Desktop\ZedGraph-4.9-CVS\demo\ZedGraph.Demo\StepChartDemo.cs
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0F);
zgMain.AxisChange();
// Add one step to the max scale value to leave room for the labels
myPane.YAxis.Scale.Max += myPane.YAxis.Scale.MajorStep;
//计算统计信息
statResult = new StatResult();
Summation = 0;
statResult.Appear = 0;
statResult.Appear1 = 0;
statResult.HitAward = yValue.Length - 1;
statResult.CurValue = Convert.ToInt32(yValue[yValue.Length - 1].ToString());
for (int i = 0; i < statResult.HitAward; i++)
{
int curValue = Convert.ToInt32(yValue[i].ToString());
Summation += curValue;
//当前期数出现次数
if (curValue == statResult.CurValue && i != statResult.HitAward)
{
statResult.Appear += 1;
}
//当前期数正负一期出现次数
if (statResult.CurValue >= curValue - 1 && statResult.CurValue <= curValue + 1 && i != statResult.HitAward)
{
statResult.Appear1 += 1;
}
}
//平均期数
statResult.Average = Summation / yValue.Length;
//推荐指数待写
statResult.Commend = 0;
}
#endregion
#region//选择显示哪个层
/// <summary>
/// 是否显示图表层
/// </summary>
/// <param name="isTrue">是否显示图表层</param>
private void ShowChartPanl(string btnName)
{
//因为btnQuery查询显示结果时经常出现累积显示的现象,所以把查询和其他统计结果分开显示
switch (btnName)
{
case "btnQuery":
plView.Visible = true;
dgvQuery.Visible = true;
dgwHistoryView.Visible = false ;
plChart.Visible = false;
break;
case "btnStat":
plView.Visible = true;
dgvQuery.Visible = false ;
dgwHistoryView.Visible = true ;
plChart.Visible = false;
break;
case "btnStatMap":
plView.Visible = true;
dgvQuery.Visible = false ;
dgwHistoryView.Visible = true ;
plChart.Visible = false;
break;
case "btnStatAll":
plView.Visible = true ;
dgvQuery.Visible = false ;
dgwHistoryView.Visible = true ;
plChart.Visible = false ;
break;
default:
plView.Visible = false;
dgvQuery.Visible = true;
dgwHistoryView.Visible = false;
plChart.Visible = true;
break;
}
}
#endregion
#region//显示统计信息
/// <summary>
/// 显示统计信息
/// </summary>
/// <param name="statResult">统计结果对象</param>
private void ShowStatInfo(StatResult statResult)
{
tsslCurValue.Text = "当前期数:" + statResult.CurValue.ToString();
tsslAverage.Text = "平均期数为:" + statResult.Average.ToString();
tsslHitAward.Text = "当前球出现次数:" + statResult.HitAward.ToString();
tsslAppear.Text = "当前期数出现次数:" + statResult.Appear.ToString();
tsslAppear1.Text = "正负一期的出现次数:" + statResult.Appear1.ToString();
tsslCommend.Text = "推荐指数:";
}
#endregion
private void btnStatAll_Click(object sender, EventArgs e)
{
int statNum; //统计期数
ArrayList tempArray; //临时数组
RedBall .StatResult[] statResult; //统计结果数组
tempArray = new ArrayList();
//判断数据的合法性
if (mtbStatNum.Text.Trim() == string.Empty)
{
MessageBox.Show("请输入统计期数!");
mtbStatNum.Focus();
return;
}
else
{
statNum = Convert.ToInt32(mtbStatNum.Text.Trim().ToString());
}
ShowChartPanl("btnStatAll");
SetDgwType("btnStatAll");
statResult = redBall.GetAllRedFrequency(statNum);
//显示数据
DataGridViewRowCollection rows = this.dgwHistoryView.Rows;
rows.Add(statResult.Length);
for (int i = 0; i < statResult.Length; i++)
{
if (statResult[i].CurRedBallNo.Length < 2)
{
this.dgwHistoryView.Rows[i].Cells[0].Value ="0" + statResult[i].CurRedBallNo.ToString();
}
else
{
this.dgwHistoryView.Rows[i].Cells[0].Value = statResult[i].CurRedBallNo.ToString();
}
this.dgwHistoryView.Rows[i].Cells[1].Value = statResult[i].CurValue .ToString ();
this.dgwHistoryView.Rows[i].Cells[2].Value = statResult[i].Appear .ToString ();
this.dgwHistoryView.Rows[i].Cells[3].Value = statResult[i].Appear1 .ToString ();
this.dgwHistoryView.Rows[i].Cells[4].Value = statResult[i].HitAward .ToString ();
this.dgwHistoryView.Rows[i].Cells[5].Value = statResult[i].Average .ToString ();
this.dgwHistoryView.Rows[i].Cells[6].Value = statResult[i].Commend .ToString ();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -