Exemple #1
0
        private void GenerateData(NBoxAndWhiskersSeries series, int nCount)
        {
            series.ClearDataPoints();

            DateTime dt     = new DateTime(2005, 5, 24, 11, 0, 0);
            Random   random = new Random();

            for (int i = 0; i < nCount; i++)
            {
                double boxLower      = 1000 + Random.NextDouble() * 200;
                double boxUpper      = boxLower + 200 + Random.NextDouble() * 200;
                double whiskersLower = boxLower - (20 + Random.NextDouble() * 300);
                double whiskersUpper = boxUpper + (20 + Random.NextDouble() * 300);

                double IQR     = (boxUpper - boxLower);
                double median  = boxLower + IQR * 0.25 + Random.NextDouble() * IQR * 0.5;
                double average = boxLower + IQR * 0.25 + Random.NextDouble() * IQR * 0.5;

                series.UpperBoxValues.Add(boxUpper);
                series.LowerBoxValues.Add(boxLower);
                series.UpperWhiskerValues.Add(whiskersUpper);
                series.LowerWhiskerValues.Add(whiskersLower);
                series.MedianValues.Add(median);
                series.AverageValues.Add(average);

                // generate date time value
                dt = dt.AddHours(12 + Random.NextDouble() * 60);
                series.XValues.Add(dt.ToOADate());

                // generate outlier values
                int outliersCount = Random.Next(5);

                NDoubleList outliers = new NDoubleList();

                for (int k = 0; k < outliersCount; k++)
                {
                    double dOutlier = 0;

                    if (Random.NextDouble() > 0.5)
                    {
                        dOutlier = boxUpper + IQR * 1.5 + Random.NextDouble() * 100;
                    }
                    else
                    {
                        dOutlier = boxLower - IQR * 1.5 - Random.NextDouble() * 100;
                    }

                    outliers.Add(dOutlier);
                }

                series.OutlierValues.Add(outliers);
            }
        }
        private void GenerateData(NBoxAndWhiskersSeries series, int nCount)
        {
            series.ClearDataPoints();

            for (int i = 0; i < nCount; i++)
            {
                double boxLower      = 1000 + Random.NextDouble() * 200;
                double boxUpper      = boxLower + 200 + Random.NextDouble() * 200;
                double whiskersLower = boxLower - (20 + Random.NextDouble() * 300);
                double whiskersUpper = boxUpper + (20 + Random.NextDouble() * 300);

                double IQR     = (boxUpper - boxLower);
                double median  = boxLower + IQR * 0.25 + Random.NextDouble() * IQR * 0.5;
                double average = boxLower + IQR * 0.25 + Random.NextDouble() * IQR * 0.5;

                series.UpperBoxValues.Add(boxUpper);
                series.LowerBoxValues.Add(boxLower);
                series.UpperWhiskerValues.Add(whiskersUpper);
                series.LowerWhiskerValues.Add(whiskersLower);
                series.MedianValues.Add(median);
                series.AverageValues.Add(average);

                int outliersCount = Random.Next(5);

                NDoubleList outliers = new NDoubleList();

                for (int k = 0; k < outliersCount; k++)
                {
                    double dOutlier = 0;

                    if (Random.NextDouble() > 0.5)
                    {
                        dOutlier = boxUpper + IQR * 1.5 + Random.NextDouble() * 100;
                    }
                    else
                    {
                        dOutlier = boxLower - IQR * 1.5 - Random.NextDouble() * 100;
                    }

                    outliers.Add(dOutlier);
                }

                series.OutlierValues.Add(outliers);
            }
        }
Exemple #3
0
        private void ChartTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            NChart chart = nChartControl1.Charts[0];

            chart.Series.Clear();
            const int numDataPoints = 50;

            switch (ChartTypeComboBox.SelectedIndex)
            {
            case 0:                     // Area
            {
                NAreaSeries area = new NAreaSeries();
                area.DataLabelStyle.Visible = false;
                area.VerticalAxisRangeMode  = AxisRangeMode.ViewRange;

                GenerateData(area, 100.0, numDataPoints, new NRange1DD(60, 140));
                chart.Series.Add(area);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NValueTimelineScaleConfigurator();
            }
            break;

            case 1:                     // Bar
            {
                NBarSeries bar = new NBarSeries();
                bar.DataLabelStyle.Visible = false;
                bar.VerticalAxisRangeMode  = AxisRangeMode.ViewRange;

                GenerateData(bar, 100.0, numDataPoints, new NRange1DD(60, 140));
                chart.Series.Add(bar);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NValueTimelineScaleConfigurator();
            }
            break;

            case 2:                     // Box And Whiskers
            {
                NBoxAndWhiskersSeries boxAndWhiskers = new NBoxAndWhiskersSeries();
                boxAndWhiskers.VerticalAxisRangeMode = AxisRangeMode.ViewRange;

                for (int i = 0; i < 40; i++)
                {
                    double boxLower      = 1000 + Random.NextDouble() * 200;
                    double boxUpper      = boxLower + 200 + Random.NextDouble() * 200;
                    double whiskersLower = boxLower - (20 + Random.NextDouble() * 300);
                    double whiskersUpper = boxUpper + (20 + Random.NextDouble() * 300);

                    double IQR     = (boxUpper - boxLower);
                    double median  = boxLower + IQR * 0.25 + Random.NextDouble() * IQR * 0.5;
                    double average = boxLower + IQR * 0.25 + Random.NextDouble() * IQR * 0.5;

                    boxAndWhiskers.UpperBoxValues.Add(boxUpper);
                    boxAndWhiskers.LowerBoxValues.Add(boxLower);
                    boxAndWhiskers.UpperWhiskerValues.Add(whiskersUpper);
                    boxAndWhiskers.LowerWhiskerValues.Add(whiskersLower);
                    boxAndWhiskers.MedianValues.Add(median);
                    boxAndWhiskers.AverageValues.Add(average);

                    int outliersCount = Random.Next(5);

                    NDoubleList outliers = new NDoubleList();

                    for (int k = 0; k < outliersCount; k++)
                    {
                        double dOutlier = 0;

                        if (Random.NextDouble() > 0.5)
                        {
                            dOutlier = boxUpper + IQR * 1.5 + Random.NextDouble() * 100;
                        }
                        else
                        {
                            dOutlier = boxLower - IQR * 1.5 - Random.NextDouble() * 100;
                        }

                        outliers.Add(dOutlier);
                    }

                    boxAndWhiskers.OutlierValues.Add(outliers);
                }

                chart.Series.Add(boxAndWhiskers);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator();
            }
            break;

            case 3:                     // Error Bar
            {
                NErrorBarSeries errorBar = new NErrorBarSeries();
                errorBar.VerticalAxisRangeMode = AxisRangeMode.ViewRange;

                double y;
                double x = 50.0;

                for (int i = 0; i < 50; i++)
                {
                    y  = 20 + Random.NextDouble() * 30;
                    x += 2.0 + Random.NextDouble() * 2;

                    errorBar.Values.Add(y);
                    errorBar.LowerErrorsY.Add(1 + Random.NextDouble());
                    errorBar.UpperErrorsY.Add(1 + Random.NextDouble());

                    errorBar.XValues.Add(x);
                    errorBar.LowerErrorsX.Add(1 + Random.NextDouble());
                    errorBar.UpperErrorsX.Add(1 + Random.NextDouble());
                }

                chart.Series.Add(errorBar);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator();
            }
            break;

            case 4:                     // "Float Bar");
            {
                NFloatBarSeries floatBar = new NFloatBarSeries();

                floatBar.VerticalAxisRangeMode = AxisRangeMode.ViewRange;

                // generate Y values
                for (int i = 0; i < 100; i++)
                {
                    double dBeginValue = Random.NextDouble() * 5;
                    double dEndValue   = dBeginValue + 2 + Random.NextDouble();
                    floatBar.Values.Add(dBeginValue);
                    floatBar.EndValues.Add(dEndValue);
                }

                // generate X values
                DateTime dt = new DateTime(2007, 5, 24, 11, 0, 0);

                for (int i = 0; i < 100; i++)
                {
                    dt = dt.AddHours(12 + Random.NextDouble() * 60);

                    floatBar.XValues.Add(dt);
                }

                chart.Series.Add(floatBar);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NValueTimelineScaleConfigurator();
            }
            break;

            case 5:                     // Line
            {
                NLineSeries line = new NLineSeries();
                line.DataLabelStyle.Visible = false;
                line.VerticalAxisRangeMode  = AxisRangeMode.ViewRange;

                GenerateData(line, 100.0, numDataPoints, new NRange1DD(60, 140));
                chart.Series.Add(line);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NValueTimelineScaleConfigurator();
            }
            break;

            case 6:                     // Point
            {
                NPointSeries point = new NPointSeries();
                point.DataLabelStyle.Visible = false;
                point.VerticalAxisRangeMode  = AxisRangeMode.ViewRange;
                point.Size = new NLength(5);

                GenerateData(point, 100.0, numDataPoints, new NRange1DD(60, 140));
                chart.Series.Add(point);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NLinearScaleConfigurator();
            }
            break;

            case 7:                     // Stock
            {
                // setup stock series
                NStockSeries stock = (NStockSeries)chart.Series.Add(SeriesType.Stock);
                stock.DataLabelStyle.Visible   = false;
                stock.UpFillStyle              = new NColorFillStyle(Color.White);
                stock.UpStrokeStyle.Color      = Color.Black;
                stock.DownFillStyle            = new NColorFillStyle(Color.Crimson);
                stock.DownStrokeStyle.Color    = Color.Crimson;
                stock.HighLowStrokeStyle.Color = Color.Black;
                stock.CandleWidth              = new NLength(1.2f, NRelativeUnit.ParentPercentage);
                stock.UseXValues            = true;
                stock.InflateMargins        = true;
                stock.VerticalAxisRangeMode = AxisRangeMode.ViewRange;

                // add some stock items
                GenerateOHLCData(stock, 100.0, numDataPoints, new NRange1DD(60, 140));
                FillStockDates(stock, numDataPoints);
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = new NValueTimelineScaleConfigurator();
            }
            break;
            }

            nChartControl1.Refresh();
        }