⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmbluechart.cs

📁 我自己开发的双色球预测软件
💻 CS
📖 第 1 页 / 共 2 页
字号:
//**************************************************************************************************************
//* 本模块主要功能:使用图表统计篮球出现的频率
//*
//* 版权: zsjt
//* 作者: 赵现发
//* 时间: 2008年1月15日
//* (******* 请保留以上信息 *******)
//**************************************************************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using System.Collections;
using DataAccessLayer;

namespace cpzh
{
    public partial class frmBlueChart : Form
    {
        private OLEDBAccessObj dbObj;
        private HistoryAnalyse historyAnalyse;

        struct StatResult                           //蓝球统计结果
        {
            public string CurBuleBallNo;            //当前蓝球号码
            public int CurValue;                    //当前期数
            public int Average;                     //平均期数
            public int HitAward;                    //中奖次数
            public int Appear;                      //当前期数出现次数
            public int Appear2;                     //当前期数正负两期出现次数
            public int Commend;                     //推荐指数,
                                                    //300期没有出现过大于当前期数 加**
                                                    //200期没有出现过大于当前期数 加*
                                                    //大于40 加*
                                                    //大于60 加**
                                                    //300期内出现超过40 加*
                                                    //200期内正负两期范围出现超过3次 加*
                                                    //200期内正负3期范围出现超过3次 加*
        }
        private StatResult statResult;              //蓝球统计结果

        public frmBlueChart()
        {
            this.dbObj = new OLEDBAccessObj();
            this.dbObj.ConnectDB();
            this.historyAnalyse = new HistoryAnalyse(this.dbObj);

            InitializeComponent();
        }

        private void frmBlueChart_Load(object sender, EventArgs e)
        {
            
            //ShowChart("01",150);
        }
        #region//显示统计篮球数字出现频率图表
        /// <summary>
        /// 显示统计篮球数字出现频率图表
        /// </summary>
        /// <param name="blueBallNo">篮球数字</param>
        /// <param name="statNum" >需要统计的期数</param>
        private void ShowChart(string blueBallNo, int statNum)
        {
            //转换数组
            double MaxValue = 0;             //最大值
            string[][] blueBallData;
            ArrayList tempArray=new ArrayList ();

            tempArray =historyAnalyse.GetBlueFrequency (blueBallNo ,statNum );
            if(tempArray .Count ==0)
            {
                MessageBox.Show ("没有查到数据!");
                return ;
            }
            blueBallData =new string [tempArray .Count][];
            tempArray.CopyTo(blueBallData);

            plChart.Controls.Clear();
            ZedGraph.ZedGraphControl zgMain = new ZedGraph.ZedGraphControl();
            zgMain.Dock = System.Windows.Forms.DockStyle.Fill;
            plChart.Controls.Add(zgMain);

            // Get a reference to the GraphPane instance in the ZedGraphControl
            
            GraphPane myPane = zgMain.GraphPane;

            // Set the titles and axis labels

            myPane.Title.Text = "蓝球历史数据分布图";
            myPane.XAxis.Title.Text = "出现次数";
            myPane.YAxis.Title.Text = "间隔期数";
            //myPane.Y2Axis.Title.Text = "Parameter B";

            // Make up some data points based on the Sine function
            PointPairList list = new PointPairList();
            //PointPairList list2 = new PointPairList();
            for (int i = 0; i < blueBallData.Length ; i++)
            {
                double x = (double)blueBallData.Length-i-1;
                double y = Convert.ToDouble ( blueBallData [i][1].ToString ());
                if (y > MaxValue)
                {
                    MaxValue = y;
                }
                //double y2 = y * 13.5;
                list.Add(x, y);
                //list2.Add(x, y2);
            }
            
            // Generate a red curve with diamond symbols, and "Alpha" in the legend
            LineItem myCurve = myPane.AddCurve("蓝球" + blueBallNo,
                list, Color.Blue, SymbolType.Diamond);
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Generate a blue curve with circle symbols, and "Beta" in the legend
            //myCurve = myPane.AddCurve("Beta",
            //    list2, Color.Blue, SymbolType.Circle);
            //// Fill the symbols with white
            //myCurve.Symbol.Fill = new Fill(Color.White);
            //// Associate this curve with the Y2 axis
            //myCurve.IsY2Axis = true;

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Blue;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            // Manually set the axis range
            myPane.YAxis.Scale.Min = 0;
            myPane.YAxis.Scale.Max = MaxValue+2 ;

            // Enable the Y2 axis display
            //myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue
            //myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            //myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;
            //// turn off the opposite tics so the Y2 tics don't show up on the Y axis
            //myPane.Y2Axis.MajorTic.IsOpposite = false;
            //myPane.Y2Axis.MinorTic.IsOpposite = false;
            //// Display the Y2 axis grid lines
            //myPane.Y2Axis.MajorGrid.IsVisible = true;
            //// Align the Y2 axis labels so they are flush to the axis
            //myPane.Y2Axis.Scale.Align = AlignP.Inside;

            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);

            // Add a text box with instructions
            //TextObj text = new TextObj(
            //    "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse",
            //    0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
            //text.FontSpec.StringAlignment = StringAlignment.Near;
            //myPane.GraphObjList.Add(text);

            // Enable scrollbars if needed
            zgMain.IsShowHScrollBar = true;
            zgMain.IsShowVScrollBar = true;
            zgMain.IsAutoScrollRange = true;
            //zgMain.IsScrollY2 = true;

            // OPTIONAL: Show tooltips when the mouse hovers over a point
            zgMain.IsShowPointValues = true;
            zgMain.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler);

            // OPTIONAL: Add a custom context menu item
            zgMain.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(
                            MyContextMenuBuilder);

            // OPTIONAL: Handle the Zoom Event
            zgMain.ZoomEvent += new ZedGraphControl.ZoomEventHandler(MyZoomEvent);

            // Size the control to fit the window
            //SetSize();

            // Tell ZedGraph to calculate the axis ranges
            // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
            // up the proper scrolling parameters
            zgMain.AxisChange();
            // Make sure the Graph gets redrawn
            zgMain.Invalidate();

        }

        /// <summary>
        /// 使用彩色立柱显示图表
        /// </summary>
        /// <param name="blueBallNo">蓝球号码</param>
        /// <param name="statNum">统计的期数</param>
        private void ShowChart1(string blueBallNo, int statNum)
        {
            //转换数组
            double MaxValue = 0;             //最大值
            string[][] blueBallData;
            ArrayList tempArray = new ArrayList();
            double[] yValue;                //y值数组
            int Summation;                   //总和

            tempArray = historyAnalyse.GetBlueFrequency(blueBallNo, statNum);
            if (tempArray.Count == 0)
            {
                MessageBox.Show("没有查到数据!");
                return;
            }
            blueBallData = new string[tempArray.Count][];
            tempArray.CopyTo(blueBallData);
            //把string数组转换成double数组,只有间隔期数,没有序号
            yValue = new double[blueBallData.Length];
            
            for (int i = 0; i < yValue.Length; i++)
            {
                yValue[yValue.Length-i-1] = Convert.ToDouble(blueBallData[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("蓝球" + blueBallNo.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 = 5;

            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;

            //计算统计信息
            Summation = 0;
            statResult.Appear = 0;
            statResult.Appear2 = 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 - 2 && statResult.CurValue <= curValue + 2 && i != statResult.HitAward)
                {
                    statResult .Appear2 +=1;
                }

            }
            //平均期数
            statResult.Average = Summation / yValue.Length;
            //推荐指数待写
            statResult.Commend = 0;
        }

        /// <summary>
        /// 初始化统计结果信息
        /// </summary>
        /// <param name="statResult">结果对象</param>
        private void InitStatInfo(StatResult statResult)
        {
            statResult.CurValue = 0;
            statResult.Average = 0;
            statResult.HitAward = 0;
            statResult.Appear = 0;
            statResult.Appear2 = 0;
            statResult.Commend = 0;
        }
        /// <summary>
        /// 显示统计信息

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -