예제 #1
0
        private void getPredictionChart(int index)
        {
            PredictionChart.BeginInvoke((MethodInvoker) delegate
            {
                PositionInfo posInfo = positionInfos[index];
                List <int> yList     = posInfo.getCounts();
                List <string> xList  = posInfo.getMonths();
                xList.Sort();
                PredictionChart.Series[0].Points.DataBindXY(xList, yList);

                double k = 0, b = 0;
                new LinearRegressonProcessor(xList, yList).Calculate(out k, out b);

                int baseMonth   = new Month(xList[0]).convertToNumber();
                int month1      = new Month("2018-01").convertToNumber() - baseMonth,
                month2          = new Month("2018-02").convertToNumber() - baseMonth,
                month3          = new Month("2018-03").convertToNumber() - baseMonth;
                int prediction1 = (int)(k * month1 + b),
                prediction2     = (int)(k * month2 + b),
                prediction3     = (int)(k * month3 + b);

                predictionYearLabel1.Text = "Prediction for 2018-1: " + prediction1;
                predictionYearLabel2.Text = "Prediction for 2018-2: " + prediction2;
                predictionYearLabel3.Text = "Prediction for 2018-3: " + prediction3;

                LRText.Text = String.Format("Linear Regression Formula: y = {0:F}x + {1:F}", k, b);
            });
        }
예제 #2
0
        private void initPredictonChart()
        {
            if (!inited)
            {
                inited = true;
                List <string> tempX = new List <string>(new String[] { "1", "2", "3" });
                List <int>    tempY = new List <int>(new int[] { 1, 2, 3 });

                getPredictionChart(0);
                //标题
                PredictionChart.BeginInvoke((MethodInvoker) delegate
                {
                    PredictionChart.Series[0].Points.DataBindXY(tempX, tempY);
                    PredictionChart.Titles.Add("统计分析表");
                    PredictionChart.Titles[0].ForeColor = Color.Black;
                    PredictionChart.Titles[0].Font      = new Font("Calibri", 16f, FontStyle.Regular);
                    PredictionChart.Titles[0].Alignment = ContentAlignment.TopCenter;

                    //控件背景
                    PredictionChart.BackColor = Color.Transparent;
                    //图表区背景
                    PredictionChart.ChartAreas[0].BackColor   = Color.Transparent;
                    PredictionChart.ChartAreas[0].BorderColor = Color.Transparent;
                    //X轴标签间距
                    PredictionChart.ChartAreas[0].AxisX.Interval = 1;
                    PredictionChart.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
                    PredictionChart.ChartAreas[0].AxisX.LabelStyle.Angle       = -45;
                    PredictionChart.ChartAreas[0].AxisX.TitleFont      = new Font("Calibri", 14f, FontStyle.Regular);
                    PredictionChart.ChartAreas[0].AxisX.TitleForeColor = Color.Black;

                    //X坐标轴颜色
                    PredictionChart.ChartAreas[0].AxisX.LineColor            = ColorTranslator.FromHtml("#38587a");;
                    PredictionChart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black;
                    PredictionChart.ChartAreas[0].AxisX.LabelStyle.Font      = new Font("Calibri", 10f, FontStyle.Regular);

                    //X轴网络线条
                    PredictionChart.ChartAreas[0].AxisX.MajorGrid.Enabled   = true;
                    PredictionChart.ChartAreas[0].AxisX.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");

                    //Y坐标轴颜色
                    PredictionChart.ChartAreas[0].AxisY.LineColor            = ColorTranslator.FromHtml("#38587a");
                    PredictionChart.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black;
                    PredictionChart.ChartAreas[0].AxisY.LabelStyle.Font      = new Font("Calibri", 10f, FontStyle.Regular);
                    //Y坐标轴标题
                    PredictionChart.ChartAreas[0].AxisY.Title           = "职位数目";
                    PredictionChart.ChartAreas[0].AxisY.TitleFont       = new Font("Calibri", 10f, FontStyle.Regular);
                    PredictionChart.ChartAreas[0].AxisY.TitleForeColor  = Color.Black;
                    PredictionChart.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Rotated270;
                    //Y轴网格线条
                    PredictionChart.ChartAreas[0].AxisY.MajorGrid.Enabled   = true;
                    PredictionChart.ChartAreas[0].AxisY.MajorGrid.LineColor = ColorTranslator.FromHtml("#2c4c6d");
                    PredictionChart.ChartAreas[0].AxisY2.LineColor          = Color.Transparent;
                    PredictionChart.ChartAreas[0].BackGradientStyle         = GradientStyle.TopBottom;
                    Legend legend = new Legend("legend");
                    legend.Title  = "legendTitle";

                    PredictionChart.Series[0].XValueType     = ChartValueType.String;  //设置X轴上的值类型
                    PredictionChart.Series[0].Label          = "#VAL";                 //设置显示X Y的值
                    PredictionChart.Series[0].LabelForeColor = Color.Black;
                    PredictionChart.Series[0].ToolTip        = "#VALX:#VAL";           //鼠标移动到对应点显示数值
                    PredictionChart.Series[0].ChartType      = SeriesChartType.Column; //图类型


                    PredictionChart.Series[0].Color               = Color.Lime;
                    PredictionChart.Series[0].LegendText          = legend.Name;
                    PredictionChart.Series[0].IsValueShownAsLabel = true;
                    PredictionChart.Series[0].LabelForeColor      = Color.Black;
                    PredictionChart.Series[0].CustomProperties    = "DrawingStyle = Cylinder";
                    PredictionChart.Legends.Add(legend);
                    PredictionChart.Legends[0].Position.Auto = false;
                    //PredictionChart.Series[0].Points[0].Color = Color.Black;
                    PredictionChart.Series[0].Palette = ChartColorPalette.SeaGreen;
                    PredictionChart.Visible           = true;
                });
            }
        }