Exemple #1
0
        private void ShowHistogram(Func <double, double> p, Func <double, double> g, int[] data, double min, double max)
        {
            ResetChart();
            chart.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
            chart.ChartAreas[0].AxisY.Minimum          = 0;
            Series series = new Series("Histogram")
            {
                ChartType = SeriesChartType.Column,
                Color     = Color.Gray
            };
            Series seriesP = new Series("p(x)")
            {
                ChartType = SeriesChartType.Line,
                Color     = Color.Blue,
            };
            Series seriesG = new Series("g(x)")
            {
                ChartType = SeriesChartType.Line,
                Color     = Color.Green,
            };

            double step = (max - min) / data.Length;

            for (int i = 0; i < data.Length; i++)
            {
                double x = Math.Round(step * i + min, 3);
                series.Points.Add(new DataPoint(x, data[i]));
            }

            double scaleP = data[0] / g(min);

            step = (max - min) / 500;
            for (int j = 0; j < 500; j++)
            {
                double x = Math.Round(step * j + min, 3);
                seriesP.Points.Add(new DataPoint(x, p(x) * scaleP));
                seriesG.Points.Add(new DataPoint(x, g(x) * scaleP));
            }
            chart.Series.Clear();
            chart.Series.Add(series);
            chart.Series.Add(seriesP);
            chart.Series.Add(seriesG);

            Series seriesLine = new Series("X1, X2")
            {
                ChartType   = SeriesChartType.Point,
                Color       = Color.Red,
                BorderWidth = 2,
            };
            var distr = _est.MakeDistr(0.95);

            seriesLine.Points.AddXY(distr.X1, p(distr.X1));
            seriesLine.Points.AddXY(distr.X1, g(distr.X1));
            seriesLine.Points.AddXY(distr.X2, p(distr.X2));
            seriesLine.Points.AddXY(distr.X2, g(distr.X2));
            //chart1.Series.Add(seriesLine);
            Refresh();
        }