Example #1
0
        private void FinancialMarkerCombo_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            NChart       chart     = nChartControl1.Charts[0];
            NStockSeries stock     = (NStockSeries)chart.Series[chart.Series.Count - 1];
            NLineStudy   lineStudy = null;
            Color        lineColor = Color.Crimson;

            switch (FinancialMarkerCombo.SelectedIndex)
            {
            case 0:
                lineStudy = new NFibonacciArcs();
                TrendlineModeCombo.Enabled = false;
                break;

            case 1:
                lineStudy = new NFibonacciFans();
                TrendlineModeCombo.Enabled = true;
                break;

            case 2:
                lineStudy = new NFibonacciRetracements();
                ((NFibonacciRetracements)lineStudy).RetracementsStrokeStyle.Color = lineColor;
                TrendlineModeCombo.Enabled = true;
                break;

            case 3:
                lineStudy = new NSpeedResistanceLines();
                TrendlineModeCombo.Enabled = true;
                break;

            case 4:
                lineStudy = new NQuadrantLines();
                ((NQuadrantLines)lineStudy).CentralLineStrokeStyle.Color = lineColor;
                TrendlineModeCombo.Enabled = false;
                break;

            case 5:
                lineStudy = new NTrendLine();
                TrendlineModeCombo.Enabled = true;
                break;

            default:
                return;
            }

            UpdateLineStudyAnchor(stock, lineStudy);

            // set the primary line color
            lineStudy.StrokeStyle.Color = lineColor;

            InsertFinancialMarker(chart, lineStudy);
            SetTextVisibility();
            lineStudy.TrendLineMode = (TrendLineMode)TrendlineModeCombo.SelectedIndex;

            nChartControl1.Refresh();
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                LineStudyDropDownList.Items.Add("Fibonacci Arcs");
                LineStudyDropDownList.Items.Add("Fibonacci Fans");
                LineStudyDropDownList.Items.Add("Fibonacci Retracements");
                LineStudyDropDownList.Items.Add("Speed Resistance Lines");
                LineStudyDropDownList.Items.Add("Quadrant Lines");
                LineStudyDropDownList.Items.Add("Trend Line");

                WebExamplesUtilities.FillComboWithEnumValues(TrendlineModeDropDownList, typeof(TrendLineMode));

                // form controls
                LineStudyDropDownList.SelectedIndex     = 0;
                TrendlineModeDropDownList.SelectedIndex = 1;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set a chart title
            NLabel title = new NLabel();

            title.Text = "Line Studies - " + LineStudyDropDownList.SelectedItem.Text;
            title.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            nChartControl1.Panels.Add(title);

            // no legend
            nChartControl1.Legends.Clear();

            // setup chart
            NChart chart = nChartControl1.Charts[0];

            chart.BoundsMode = BoundsMode.Stretch;

            // setup X axis
            NAxis axis = chart.Axis(StandardAxis.PrimaryX);
            NDateTimeScaleConfigurator timeScaleConfigurator = new NDateTimeScaleConfigurator();

            axis.ScaleConfigurator = timeScaleConfigurator;
            timeScaleConfigurator.EnableUnitSensitiveFormatting    = false;
            timeScaleConfigurator.LabelValueFormatter              = new NDateTimeValueFormatter("MMM yy");
            timeScaleConfigurator.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            timeScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
            timeScaleConfigurator.InnerMajorTickStyle.LineStyle.Width = new NLength(0, NGraphicsUnit.Pixel);
            timeScaleConfigurator.RoundToTickMin      = false;
            timeScaleConfigurator.RoundToTickMax      = false;
            timeScaleConfigurator.LabelGenerationMode = LabelGenerationMode.SingleLevel;

            // setup Y axis
            axis = chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator linearScaleConfigurator = (NLinearScaleConfigurator)axis.ScaleConfigurator;

            linearScaleConfigurator.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            linearScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Left, false);
            linearScaleConfigurator.InnerMajorTickStyle.LineStyle.Width = new NLength(0, NGraphicsUnit.Pixel);

            // add interlaced stripe
            NScaleStripStyle stripStyle = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1);

            stripStyle.Interlaced = true;
            stripStyle.SetShowAtWall(ChartWallType.Back, true);
            linearScaleConfigurator.StripStyles.Add(stripStyle);

            Color customColor = Color.FromArgb(150, 150, 200);

            // setup the stock series
            NStockSeries stock = (NStockSeries)chart.Series.Add(SeriesType.Stock);

            stock.DataLabelStyle.Visible   = false;
            stock.CandleStyle              = CandleStyle.Bar;
            stock.CandleWidth              = new NLength(0.3f, NRelativeUnit.ParentPercentage);
            stock.HighLowStrokeStyle.Color = customColor;
            stock.UpStrokeStyle.Width      = new NLength(0);
            stock.DownStrokeStyle.Width    = new NLength(0);
            stock.UpFillStyle              = new NColorFillStyle(Color.LightGreen);
            stock.DownFillStyle            = new NColorFillStyle(customColor);
            stock.UseXValues     = true;
            stock.InflateMargins = true;

            GenerateData(stock);

            // apply layout
            ApplyLayoutTemplate(0, nChartControl1, chart, title, null);

            // create line study
            NLineStudy lineStudy = null;
            Color      lineColor = Color.Crimson;

            switch (LineStudyDropDownList.SelectedIndex)
            {
            case 0:
                lineStudy = new NFibonacciArcs();
                break;

            case 1:
                lineStudy = new NFibonacciFans();
                break;

            case 2:
                lineStudy = new NFibonacciRetracements();
                ((NFibonacciRetracements)lineStudy).RetracementsStrokeStyle.Color = lineColor;
                break;

            case 3:
                lineStudy = new NSpeedResistanceLines();
                break;

            case 4:
                lineStudy = new NQuadrantLines();
                ((NQuadrantLines)lineStudy).CentralLineStrokeStyle.Color = lineColor;
                break;

            case 5:
                lineStudy = new NTrendLine();
                break;

            default:
                return;
            }

            // attach the line study to the stock series
            lineStudy.BeginPoint = GetLowPointFromStock(stock, 20);
            lineStudy.EndPoint   = GetHighPointFromStock(stock, 80);

            // set the primary line color
            lineStudy.StrokeStyle.Color = lineColor;

            InsertFinancialMarker(chart, lineStudy);
            TrendlineModeDropDownList.Enabled = lineStudy is NTrendLine;


            // set trend line mode
            NTrendLine trend = chart.Series[0] as NTrendLine;

            lineStudy.TrendLineMode = (TrendLineMode)TrendlineModeDropDownList.SelectedIndex;

            // set text visibility
            lineStudy.ShowTexts = ShowTextsCheckBox.Checked;
        }