Ejemplo n.º 1
0
        private void SetupTimeScale(NAxis axis)
        {
            NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle            = true;
            scaleX.FirstRow.InnerTickStyle.Visible  = false;
            scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle           = true;
            scaleX.SecondRow.InnerTickStyle.Visible = false;
            scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle            = true;
            scaleX.ThirdRow.InnerTickStyle.Visible  = false;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;

            axis.ScaleConfigurator = scaleX;
        }
Ejemplo n.º 2
0
        public void InitChart(NCartesianChart chart)
        {
            // set layout related properties
            chart.BoundsMode = BoundsMode.Stretch;
            chart.DockMode   = PanelDockMode.Fill;
            chart.Margins    = new NMarginsL(10, 0, 10, 10);
            nChartControl1.Panels.Add(chart);

            // add interlace stripes
            NLinearScaleConfigurator linearScale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NLinearScaleConfigurator;
            NScaleStripStyle         stripStyle  = new NScaleStripStyle(new NColorFillStyle(Color.Beige), null, true, 0, 0, 1, 1);

            stripStyle.Interlaced  = true;
            stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            linearScale.StripStyles.Add(stripStyle);

            // show X axis zooming and scrolling
            chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;

            // apply work calendar to the X axis
            NWorkCalendar calendar    = new NWorkCalendar();
            NWeekDayRule  weekDayRule = new NWeekDayRule();
            WeekDayBit    weekDays    = WeekDayBit.None;

            weekDays            |= WeekDayBit.Monday;
            weekDays            |= WeekDayBit.Tuesday;
            weekDays            |= WeekDayBit.Wednesday;
            weekDays            |= WeekDayBit.Thursday;
            weekDays            |= WeekDayBit.Friday;
            weekDayRule.WeekDays = weekDays;
            weekDayRule.Schedule.SetHourRange(0, 24, false);
            calendar.Rules.Add(weekDayRule);

            // apply calendar to scale
            NRangeTimelineScaleConfigurator timeline = new NRangeTimelineScaleConfigurator();

            timeline.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            timeline.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            timeline.FirstRow.UseGridStyle           = true;
            timeline.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            timeline.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            timeline.SecondRow.UseGridStyle          = true;
            timeline.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            timeline.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            timeline.ThirdRow.UseGridStyle           = true;

            timeline.EnableCalendar = false;
            timeline.Calendar       = calendar;
            timeline.ThirdRow.EnableUnitSensitiveFormatting = false;

            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = timeline;

            // generate data for this calendar
            AddData(chart, calendar);
        }
Ejemplo n.º 3
0
        public NevronChartForm( )
        {
            InitializeComponent();

            NChart chart = this.nevronChart.Charts[0];

            // setup X axis
            NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle            = true;
            scaleX.FirstRow.InnerTickStyle.Visible  = false;
            scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle           = true;
            scaleX.SecondRow.InnerTickStyle.Visible = false;
            scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle            = true;
            scaleX.ThirdRow.InnerTickStyle.Visible  = false;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

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

            scaleY.OuterMajorTickStyle.Length  = new NLength(3, NGraphicsUnit.Point);
            scaleY.InnerMajorTickStyle.Visible = false;

            NFillStyle       stripFill  = new NColorFillStyle(Color.FromArgb(234, 233, 237));
            NScaleStripStyle stripStyle = new NScaleStripStyle(stripFill, null, true, 1, 0, 1, 1);

            stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            stripStyle.Interlaced  = true;
            scaleY.StripStyles.Add(stripStyle);
        }
Ejemplo n.º 4
0
        public override void Initialize()
        {
            base.Initialize();

            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Moving Averages");

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
            title.ContentAlignment    = ContentAlignment.BottomCenter;
            title.Location            = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            // setup chart
            m_Chart            = nChartControl1.Charts[0];
            m_Chart.BoundsMode = BoundsMode.Stretch;
            m_Chart.Location   = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage), new NLength(15, NRelativeUnit.ParentPercentage));
            m_Chart.Size       = new NSizeL(new NLength(80, NRelativeUnit.ParentPercentage), new NLength(75, NRelativeUnit.ParentPercentage));

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // setup Y axis
            NAxis axis = m_Chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator linearScale = (NLinearScaleConfigurator)axis.ScaleConfigurator;

            linearScale.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            linearScale.InnerMajorTickStyle.Length = new NLength(0);

            // line series for the function
            m_Line = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_Line.DataLabelStyle.Visible = false;
            m_Line.BorderStyle.Color      = Color.Crimson;
            m_Line.BorderStyle.Width      = new NLength(2, NGraphicsUnit.Pixel);
            m_Line.UseXValues             = true;

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

            // setup the stock series
            m_Stock = (NStockSeries)m_Chart.Series.Add(SeriesType.Stock);
            m_Stock.DataLabelStyle.Visible   = false;
            m_Stock.CandleStyle              = CandleStyle.Bar;
            m_Stock.HighLowStrokeStyle.Color = customColor;
            m_Stock.UpStrokeStyle.Color      = customColor;
            m_Stock.DownStrokeStyle.Color    = customColor;
            m_Stock.UpFillStyle              = new NColorFillStyle(Color.White);
            m_Stock.DownFillStyle            = new NColorFillStyle(customColor);
            m_Stock.Legend.Mode              = SeriesLegendMode.None;
            m_Stock.OpenValues.Name          = "open";
            m_Stock.HighValues.Name          = "high";
            m_Stock.LowValues.Name           = "low";
            m_Stock.CloseValues.Name         = "close";
            m_Stock.CandleWidth              = new NLength(1, NRelativeUnit.ParentPercentage);
            m_Stock.InflateMargins           = true;
            m_Stock.UseXValues = true;

            GenerateData();

            // form controls
            m_bSkipUpdate = true;
            m_ApplyToCombo.SelectedIndex = 3;
            m_bSkipUpdate = false;

            m_FunctionCombo.Items.Add("Simple Moving Average");
            m_FunctionCombo.Items.Add("Weighted Moving Average");
            m_FunctionCombo.Items.Add("Exponential Moving Average");
            m_FunctionCombo.Items.Add("Modified Moving Average");
            m_FunctionCombo.SelectedIndex = 0;
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set a chart title
            NLabel header = nChartControl1.Labels.AddFooter("Price Indicators");

            header.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            header.ContentAlignment           = ContentAlignment.BottomRight;
            header.Location = new NPointL(
                new NLength(2, NRelativeUnit.ParentPercentage),
                new NLength(2, NRelativeUnit.ParentPercentage));

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

            chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            chart.LightModel.EnableLighting         = false;
            chart.Axis(StandardAxis.Depth).Visible  = false;
            chart.Wall(ChartWallType.Floor).Visible = false;
            chart.Wall(ChartWallType.Left).Visible  = false;
            chart.BoundsMode = BoundsMode.Stretch;
            chart.Height     = 40;
            chart.Location   = new NPointL(
                new NLength(5, NRelativeUnit.ParentPercentage),
                new NLength(15, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(80, NRelativeUnit.ParentPercentage));

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

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

            linearScale.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            linearScale.InnerMajorTickStyle.Length = new NLength(0);

            // line series for the function
            NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);

            line.DataLabelStyle.Visible = false;
            line.BorderStyle.Color      = Color.Red;
            line.BorderStyle.Width      = new NLength(2, NGraphicsUnit.Pixel);
            line.ShadowStyle.Type       = ShadowType.GaussianBlur;
            line.UseXValues             = true;

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

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

            stock.DataLabelStyle.Visible   = false;
            stock.CandleStyle              = CandleStyle.Stick;
            stock.HighLowStrokeStyle.Color = customColor;
            stock.UpStrokeStyle.Color      = customColor;
            stock.DownStrokeStyle.Color    = customColor;
            stock.UpFillStyle              = new NColorFillStyle(Color.White);
            stock.DownFillStyle            = new NColorFillStyle(customColor);
            stock.Legend.Mode              = SeriesLegendMode.None;
            stock.OpenValues.Name          = "open";
            stock.HighValues.Name          = "high";
            stock.LowValues.Name           = "low";
            stock.CloseValues.Name         = "close";
            stock.CandleWidth              = new NLength(1, NRelativeUnit.ParentPercentage);
            stock.InflateMargins           = true;
            stock.UseXValues = true;

            GenerateData(stock);

            if (!IsPostBack)
            {
                FunctionDropDownList.Items.Add("Median Price");
                FunctionDropDownList.Items.Add("Typical Price");
                FunctionDropDownList.Items.Add("Weighted Close");
                FunctionDropDownList.SelectedIndex = 0;
            }

            CalculateFunction(stock, line);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected override NWidget CreateExampleContent()
        {
            NChartView chartView = CreateCartesianChartView();

            // configure title
            chartView.Surface.Titles[0].Text = "Weekly Schedule Work Calendar";

            // configure chart
            m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);

            NRangeSeries ranges = new NRangeSeries();

            m_Chart.Series.Add(ranges);

            ranges.DataLabelStyle = new NDataLabelStyle(false);
            ranges.UseXValues     = true;

            DateTime dt   = new DateTime(2014, 4, 14);
            Random   rand = new Random();

            NRangeTimelineScale rangeTimeline = new NRangeTimelineScale();

            rangeTimeline.EnableCalendar = true;
            m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = rangeTimeline;

            NLinearScale yScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;

            yScale.MajorGridLines.Visible = true;

            // add interlaced strip
            NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);

            strip.Interlaced = true;
            yScale.Strips.Add(strip);

            yScale.Title.Text = "Weekly Workload in %";

            NWorkCalendar workCalendar = rangeTimeline.Calendar;

            // show only the working days on the scale
            NWeekDayRule weekDayRule = new NWeekDayRule(ENWeekDayBit.Monday | ENWeekDayBit.Tuesday | ENWeekDayBit.Wednesday | ENWeekDayBit.Thursday | ENWeekDayBit.Friday);

            workCalendar.Rules.Add(weekDayRule);

            // generate data for week working days
            for (int i = 0; i < 21; i++)
            {
                if (dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday)
                {
                    ranges.DataPoints.Add(new NRangeDataPoint(NDateTimeHelpers.ToOADate(dt), 0, NDateTimeHelpers.ToOADate(dt + new TimeSpan(1, 0, 0, 0)), rand.NextDouble() * 70 + 30.0d));
                }

                dt += new TimeSpan(1, 0, 0, 0);
            }

            ConfigureInteractivity(m_Chart);

            chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, false));

            return(chartView);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WebExamplesUtilities.FillComboWithValues(PeriodDropDownList, 0, 100, 10);
                PeriodDropDownList.SelectedIndex = 2;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            NFunctionCalculator calc = new NFunctionCalculator();

            nChartControl1.Settings.ShapeRenderingMode = ShapeRenderingMode.None;

            NChart chart = nChartControl1.Charts[0];

            chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            chart.BoundsMode = BoundsMode.Stretch;
            chart.Location   = new NPointL(
                new NLength(5, NRelativeUnit.ParentPercentage),
                new NLength(20, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(75, NRelativeUnit.ParentPercentage));

            NLegend legend = nChartControl1.Legends[0];

            legend.Data.ExpandMode = LegendExpandMode.ColsOnly;
            legend.Location        = new NPointL(
                new NLength(98, NRelativeUnit.ParentPercentage),
                new NLength(12, NRelativeUnit.ParentPercentage));

            // align the chart and the legend
            NSideGuideline guideline = new NSideGuideline(PanelSide.Right);

            guideline.Targets.Add(legend);
            guideline.Targets.Add(chart);
            nChartControl1.Document.RootPanel.Guidelines.Add(guideline);

            // setup X axis
            NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle            = true;
            scaleX.FirstRow.InnerTickStyle.Visible  = false;
            scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle           = true;
            scaleX.SecondRow.InnerTickStyle.Visible = false;
            scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle            = true;
            scaleX.ThirdRow.InnerTickStyle.Visible  = false;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // setup primary Y axis
            NAxis axisY1 = chart.Axis(StandardAxis.PrimaryY);

            axisY1.Anchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 45, 100);

            NLinearScaleConfigurator scaleY1 = (NLinearScaleConfigurator)axisY1.ScaleConfigurator;

            scaleY1.RulerStyle.Height                   = new NLength(2, NGraphicsUnit.Pixel);
            scaleY1.MajorGridStyle.ShowAtWalls          = new ChartWallType[] { ChartWallType.Back };
            scaleY1.InnerMajorTickStyle.LineStyle.Width = new NLength(0);

            // setup secondary Y axis
            NAxis axisY2 = chart.Axis(StandardAxis.SecondaryY);

            axisY2.Visible = true;
            axisY2.Anchor  = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 0, 40);

            NLinearScaleConfigurator scaleY2 = (NLinearScaleConfigurator)axisY2.ScaleConfigurator;

            scaleY2.RulerStyle.Height                   = new NLength(2, NGraphicsUnit.Pixel);
            scaleY2.MajorGridStyle.ShowAtWalls          = new ChartWallType[] { ChartWallType.Back };
            scaleY2.InnerMajorTickStyle.LineStyle.Width = new NLength(0);

            Color color1 = Color.FromArgb(100, 100, 150);
            Color color2 = Color.FromArgb(200, 120, 120);
            Color color3 = Color.FromArgb(100, 150, 100);

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

            stock.DataLabelStyle.Visible = false;
            stock.CandleStyle            = CandleStyle.Stick;
            stock.UpStrokeStyle.Color    = color1;
            stock.DownStrokeStyle.Color  = color2;
            stock.Legend.Mode            = SeriesLegendMode.None;
            stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            stock.UseXValues             = true;
            stock.InflateMargins         = true;

            // Add line series for ADX
            NLineSeries lineADX = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineADX.DisplayOnAxis(StandardAxis.PrimaryY, false);
            lineADX.DisplayOnAxis(StandardAxis.SecondaryY, true);
            lineADX.BorderStyle.Color = Color.LimeGreen;
            lineADX.Name = "ADX";
            lineADX.DataLabelStyle.Visible = false;

            // Add line series for +DI
            NLineSeries lineDIPos = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineDIPos.MultiLineMode = MultiLineMode.Overlapped;
            lineDIPos.DisplayOnAxis(StandardAxis.PrimaryY, false);
            lineDIPos.DisplayOnAxis(StandardAxis.SecondaryY, true);
            lineDIPos.BorderStyle.Color = Color.Red;
            lineDIPos.Name = "+DI";
            lineDIPos.DataLabelStyle.Visible = false;

            // Add line series for -DI
            NLineSeries lineDINeg = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineDINeg.MultiLineMode = MultiLineMode.Overlapped;
            lineDINeg.DisplayOnAxis(StandardAxis.PrimaryY, false);
            lineDINeg.DisplayOnAxis(StandardAxis.SecondaryY, true);
            lineDINeg.BorderStyle.Color = Color.Blue;
            lineDINeg.Name = "-DI";
            lineDINeg.DataLabelStyle.Visible = false;

            // add arguments for function calculator
            stock.CloseValues.Name = "close";
            stock.HighValues.Name  = "high";
            stock.LowValues.Name   = "low";
            calc.Arguments.Add(stock.CloseValues);
            calc.Arguments.Add(stock.HighValues);
            calc.Arguments.Add(stock.LowValues);

            // form controls
            lineDIPos.Visible = ShowPosDICheckBox.Checked;
            lineDINeg.Visible = ShowNegDICheckBox.Checked;
            lineADX.Visible   = ShowADXCheckBox.Checked;

            // add header
            NLabel header = nChartControl1.Labels.AddHeader("Directional Movement");

            header.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            header.ContentAlignment           = ContentAlignment.BottomRight;
            header.Location = new NPointL(
                new NLength(2, NRelativeUnit.ParentPercentage),
                new NLength(2, NRelativeUnit.ParentPercentage));

            GenerateData(stock);

            UpdateFunctions(stock, lineDIPos, lineDINeg, lineADX, calc);
        }
Ejemplo n.º 8
0
        private void CreateWorkCalendar()
        {
            if (m_Updating)
            {
                return;
            }

            if (m_Chart != null)
            {
                m_Chart.Axis(StandardAxis.PrimaryX).PagingView.Enabled = false;
                m_Chart.Axis(StandardAxis.PrimaryY).PagingView.Enabled = false;
            }

            // create calendar
            m_Calendar = new NWorkCalendar();

            // use week days
            if (EnableWeekRuleCheckBox.Checked)
            {
                NWeekDayRule weekDayRule = new NWeekDayRule();

                WeekDayBit weekDays = WeekDayBit.None;
                if (MondayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Monday;
                }

                if (TuesdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Tuesday;
                }

                if (WednesdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Wednesday;
                }

                if (ThursdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Thursday;
                }

                if (FridayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Friday;
                }

                if (SaturdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Saturday;
                }

                if (SundayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Sunday;
                }

                if (weekDays == WeekDayBit.None)
                {
                    // cannot select all week days as non working as this leads to a scale with no
                    // working days...
                    MessageBox.Show("You cannot select all weekdays as non working.");
                    return;
                }

                weekDayRule.WeekDays = weekDays;
                weekDayRule.Schedule.SetHourRange(0, 24, false);
                m_Calendar.Rules.Add(weekDayRule);
            }

            if (EnableMonthDayRuleCheckBox.Checked)
            {
                NMonthDayRule monthDayRule = new NMonthDayRule();

                monthDayRule.Months = MonthBit.January |
                                      MonthBit.February |
                                      MonthBit.March |
                                      MonthBit.April |
                                      MonthBit.May |
                                      MonthBit.June |
                                      MonthBit.July |
                                      MonthBit.August |
                                      MonthBit.September |
                                      MonthBit.October |
                                      MonthBit.November |
                                      MonthBit.December;

                monthDayRule.Day     = (int)MonthDayUpDown.Value;
                monthDayRule.Working = WorkRadioButton.Checked;
                m_Calendar.Rules.Add(monthDayRule);
            }

            // apply calendar to scale
            NRangeTimelineScaleConfigurator timeline = new NRangeTimelineScaleConfigurator();

            timeline.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            timeline.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            timeline.FirstRow.UseGridStyle           = true;
            timeline.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            timeline.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            timeline.SecondRow.UseGridStyle          = true;
            timeline.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            timeline.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            timeline.ThirdRow.UseGridStyle           = true;

            timeline.EnableCalendar = true;
            timeline.Calendar       = m_Calendar;
            timeline.ThirdRow.EnableUnitSensitiveFormatting = false;

            if (m_Chart != null)
            {
                m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = timeline;
            }

            // generate data for this calendar
            AddData();

            if (nChartControl1 != null)
            {
                nChartControl1.Refresh();
            }
        }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WebExamplesUtilities.FillComboWithColorNames(UpStickColorDropDownList, KnownColor.Black);
                WebExamplesUtilities.FillComboWithColorNames(DownStickColorDropDownList, KnownColor.Crimson);

                // init form controls
                ShowHighLowCheckBox.Checked = true;
                ShowOpenCheckBox.Checked    = true;
                ShowCloseCheckBox.Checked   = true;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Stick Stock Chart");

            title.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;

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

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

            chart.BoundsMode = BoundsMode.Stretch;

            // setup X axis
            NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle            = true;
            scaleX.FirstRow.InnerTickStyle.Visible  = false;
            scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle           = true;
            scaleX.SecondRow.InnerTickStyle.Visible = false;
            scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle            = true;
            scaleX.ThirdRow.InnerTickStyle.Visible  = false;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

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

            scaleY.OuterMajorTickStyle.Length  = new NLength(3, NGraphicsUnit.Point);
            scaleY.InnerMajorTickStyle.Visible = false;

            NFillStyle       stripFill  = new NColorFillStyle(Color.FromArgb(234, 233, 237));
            NScaleStripStyle stripStyle = new NScaleStripStyle(stripFill, null, true, 1, 0, 1, 1);

            stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            stripStyle.Interlaced  = true;
            scaleY.StripStyles.Add(stripStyle);

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

            stock.CandleStyle            = CandleStyle.Stick;
            stock.CandleWidth            = new NLength(1.3f, NRelativeUnit.ParentPercentage);
            stock.DataLabelStyle.Visible = false;
            stock.UseXValues             = true;
            stock.InflateMargins         = true;
            stock.UpStrokeStyle.Width    = new NLength(1, NGraphicsUnit.Point);
            stock.DownStrokeStyle.Width  = new NLength(1, NGraphicsUnit.Point);
            stock.ShowClose   = ShowCloseCheckBox.Checked;
            stock.ShowOpen    = ShowOpenCheckBox.Checked;
            stock.ShowHighLow = ShowHighLowCheckBox.Checked;

            stock.UpStrokeStyle.Color   = WebExamplesUtilities.ColorFromDropDownList(UpStickColorDropDownList);
            stock.DownStrokeStyle.Color = WebExamplesUtilities.ColorFromDropDownList(DownStickColorDropDownList);

            // add some stock items
            const int count = 40;

            GenerateOHLCData(stock, count);
            FillStockDates(stock, count);

            // apply layout
            ApplyLayoutTemplate(0, nChartControl1, chart, title, null);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            NStockSeries stock;

            if (!IsPostBack)
            {
                // set a chart title
                nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

                NLabel title = nChartControl1.Labels.AddHeader("Stock Data Grouping");
                title.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
                title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;

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

                // setup chart
                NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
                chart.BoundsMode = BoundsMode.Stretch;

                NRangeSelection rs = new NRangeSelection();
                rs.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
                chart.RangeSelections.Add(rs);

                // setup X axis
                NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();
                scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
                scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
                scaleX.FirstRow.UseGridStyle            = true;
                scaleX.FirstRow.InnerTickStyle.Visible  = false;
                scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
                scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
                scaleX.SecondRow.UseGridStyle           = true;
                scaleX.SecondRow.InnerTickStyle.Visible = false;
                scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
                scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
                scaleX.ThirdRow.UseGridStyle            = true;
                scaleX.ThirdRow.InnerTickStyle.Visible  = false;

                // calendar
                NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);
                wdr.Saturday = false;
                wdr.Sunday   = false;
                scaleX.Calendar.Rules.Add(wdr);
                scaleX.EnableCalendar = true;

                // set configurator
                chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;
                chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;

                // setup Y axis
                NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;
                scaleY.OuterMajorTickStyle.Length  = new NLength(3, NGraphicsUnit.Point);
                scaleY.InnerMajorTickStyle.Visible = false;

                NFillStyle       stripFill  = new NColorFillStyle(Color.FromArgb(234, 233, 237));
                NScaleStripStyle stripStyle = new NScaleStripStyle(stripFill, null, true, 1, 0, 1, 1);
                stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
                stripStyle.Interlaced  = true;
                scaleY.StripStyles.Add(stripStyle);

                // setup stock series
                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.DataLabelStyle.Format = "open - <open>\r\nclose - <close>";

                // add some stock items
                const int numDataPoints = 1000;
                WebExamplesUtilities.GenerateOHLCData(stock, 100.0, numDataPoints, new NRange1DD(60, 140));
                FillStockDates(stock, numDataPoints, DateTime.Now - new TimeSpan((int)(numDataPoints * 1.2), 0, 0, 0));

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

                // update form controls
                CustomDateTimeSpanDropDownList.Items.Add("1 Week");
                CustomDateTimeSpanDropDownList.Items.Add("2 Weeks");
                CustomDateTimeSpanDropDownList.Items.Add("1 Month");
                CustomDateTimeSpanDropDownList.Items.Add("3 Months");

                WebExamplesUtilities.FillComboWithEnumNames(GroupingModeDropDownList, typeof(StockGroupingMode));

                CustomDateTimeSpanDropDownList.SelectedIndex = 2;
                GroupingModeDropDownList.SelectedIndex       = (int)StockGroupingMode.SynchronizeWithMajorTick;

                WebExamplesUtilities.FillComboWithPercents(GroupPercendWidthDropDownList, 10);
                GroupPercendWidthDropDownList.SelectedIndex = 2;

                WebExamplesUtilities.FillComboWithValues(MinGroupDistanceDropDownList, 2, 20, 2);
                MinGroupDistanceDropDownList.SelectedIndex = 2;
            }
            else
            {
                stock = (NStockSeries)nChartControl1.Charts[0].Series[0];
            }

            MinGroupDistanceDropDownList.Enabled   = false;
            CustomDateTimeSpanDropDownList.Enabled = false;
            GroupPercendWidthDropDownList.Enabled  = true;

            switch (GroupingModeDropDownList.SelectedIndex)
            {
            case (int)StockGroupingMode.None:
                stock.GroupingMode = StockGroupingMode.None;
                GroupPercendWidthDropDownList.Enabled = false;
                break;

            case (int)StockGroupingMode.AutoDateTimeSpan:
                stock.GroupingMode = StockGroupingMode.AutoDateTimeSpan;
                MinGroupDistanceDropDownList.Enabled = true;
                break;

            case (int)StockGroupingMode.CustomDateTimeSpan:
                stock.GroupingMode = StockGroupingMode.CustomDateTimeSpan;
                CustomDateTimeSpanDropDownList.Enabled = true;
                break;

            case (int)StockGroupingMode.SynchronizeWithMajorTick:
                stock.GroupingMode = StockGroupingMode.SynchronizeWithMajorTick;
                break;

            default:
                break;
            }

            stock.MinAutoGroupLength = new NLength((float)MinGroupDistanceDropDownList.SelectedIndex * 2 + 2, NGraphicsUnit.Point);

            switch (CustomDateTimeSpanDropDownList.SelectedIndex)
            {
            case 0:                     // 1 Week
                stock.CustomGroupStep = new NDateTimeSpan(1, NDateTimeUnit.Week);
                break;

            case 1:                     // 2 Weeks
                stock.CustomGroupStep = new NDateTimeSpan(2, NDateTimeUnit.Week);
                break;

            case 2:                     // 1 Month
                stock.CustomGroupStep = new NDateTimeSpan(1, NDateTimeUnit.Month);
                break;

            case 3:                     // 3 Months
                stock.CustomGroupStep = new NDateTimeSpan(3, NDateTimeUnit.Month);
                break;
            }

            stock.GroupPercentWidth = (float)GroupPercendWidthDropDownList.SelectedIndex * 10;
        }
Ejemplo n.º 11
0
        private NCartesianChart CreateStockChart()
        {
            NCartesianChart chart = new NCartesianChart();

            chart.DockMode            = PanelDockMode.Top;
            chart.Size                = new NSizeL(new NLength(0), new NLength(60, NRelativeUnit.ParentPercentage));
            chart.DockMargins         = new NMarginsL(10, 10, 10, 10);
            chart.BackgroundFillStyle = new NColorFillStyle(Color.FromArgb(125, Color.White));
            chart.BoundsMode          = BoundsMode.Stretch;
            chart.Padding             = new NMarginsL(10, 10, 10, 10);

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

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

            scaleY.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            scaleY.MajorGridStyle.SetShowAtWall(ChartWallType.Left, false);
            scaleY.InnerMajorTickStyle.Length = new NLength(0);

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

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

            // setup the stock series
            m_Stock                        = (NStockSeries)chart.Series.Add(SeriesType.Stock);
            m_Stock.Name                   = "Price";
            m_Stock.Legend.Mode            = SeriesLegendMode.None;
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.CandleStyle            = CandleStyle.Stick;
            m_Stock.UpStrokeStyle.Color    = Color.RoyalBlue;
            m_Stock.OpenValues.Name        = "open";
            m_Stock.HighValues.Name        = "high";
            m_Stock.LowValues.Name         = "low";
            m_Stock.CloseValues.Name       = "close";
            m_Stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            m_Stock.UseXValues             = true;
            m_Stock.InflateMargins         = true;

            return(chart);
        }
Ejemplo n.º 12
0
        public override void Initialize()
        {
            base.Initialize();

            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Bollinger Bands / Envelopes");

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
            title.ContentAlignment    = ContentAlignment.BottomCenter;
            title.Location            = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            // setup chart
            m_Chart            = nChartControl1.Charts[0];
            m_Chart.BoundsMode = BoundsMode.Stretch;
            m_Chart.Location   = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage), new NLength(15, NRelativeUnit.ParentPercentage));
            m_Chart.Size       = new NSizeL(new NLength(80, NRelativeUnit.ParentPercentage), new NLength(75, NRelativeUnit.ParentPercentage));

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // setup Y axis
            NAxis axis = m_Chart.Axis(StandardAxis.PrimaryY);
            NLinearScaleConfigurator linearScale = (NLinearScaleConfigurator)axis.ScaleConfigurator;

            linearScale.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            linearScale.InnerMajorTickStyle.Length = new NLength(0);

            // Add line series for the upper band
            m_LineUpper = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_LineUpper.DataLabelStyle.Visible = false;
            m_LineUpper.BorderStyle.Color      = Color.Green;
            m_LineUpper.UseXValues             = true;

            // Add line series for lower band
            m_LineLower = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_LineLower.DataLabelStyle.Visible = false;
            m_LineLower.BorderStyle.Color      = Color.Green;
            m_LineLower.UseXValues             = true;

            // Add line series for Simple Moving Average
            m_LineSMA = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_LineSMA.DataLabelStyle.Visible = false;
            m_LineSMA.BorderStyle.Color      = Color.Orange;
            m_LineSMA.Name       = "Simple Moving Average";
            m_LineSMA.UseXValues = true;

            Color color1 = Color.FromArgb(100, 100, 150);
            Color color2 = Color.FromArgb(200, 120, 120);

            // Setup the stock series
            m_Stock = (NStockSeries)m_Chart.Series.Add(SeriesType.Stock);
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.CandleStyle            = CandleStyle.Stick;
            m_Stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            m_Stock.UpStrokeStyle.Color    = color1;
            m_Stock.DownStrokeStyle.Color  = color2;
            m_Stock.Legend.Mode            = SeriesLegendMode.None;
            m_Stock.CloseValues.Name       = "close";
            m_Stock.UseXValues             = true;
            m_Stock.InflateMargins         = true;

            // Add arguments
            m_UpperCalculator.Arguments.Add(m_Stock.CloseValues);
            m_LowerCalculator.Arguments.Add(m_Stock.CloseValues);
            m_SMACalculator.Arguments.Add(m_Stock.CloseValues);

            GenerateData();

            // form controls
            m_FunctionCombo.Items.Add("Bollinger Bands");
            m_FunctionCombo.Items.Add("Envelopes");

            m_Updating = false;

            m_FunctionCombo.SelectedIndex = 0;
            m_ShowPricesCheck.Checked     = true;
            m_ShowAverageCheck.Checked    = true;
        }
Ejemplo n.º 13
0
        private NWorkCalendar CreateWorkCalendar()
        {
            // create calendar
            NWorkCalendar m_Calendar = new NWorkCalendar();

            // use week days
            if (EnableWeekRuleCheckBox.Checked)
            {
                NWeekDayRule weekDayRule = new NWeekDayRule();

                WeekDayBit weekDays = WeekDayBit.None;
                if (MondayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Monday;
                }

                if (TuesdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Tuesday;
                }

                if (WednesdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Wednesday;
                }

                if (ThursdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Thursday;
                }

                if (FridayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Friday;
                }

                if (SaturdayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Saturday;
                }

                if (SundayCheckBox.Checked)
                {
                    weekDays |= WeekDayBit.Sunday;
                }

                if (!(weekDays.Equals(WeekDayBit.None)))
                {
                    // cannot select all week days as non working as this leads to a scale with no
                    // working days...
                    weekDayRule.WeekDays = weekDays;
                    weekDayRule.Schedule.SetHourRange(0, 24, false);
                    m_Calendar.Rules.Add(weekDayRule);
                }
            }

            if (EnableMonthDayRuleCheckBox.Checked)
            {
                NMonthDayRule monthDayRule = new NMonthDayRule();

                monthDayRule.Months = MonthBit.January |
                                      MonthBit.February |
                                      MonthBit.March |
                                      MonthBit.April |
                                      MonthBit.May |
                                      MonthBit.June |
                                      MonthBit.July |
                                      MonthBit.August |
                                      MonthBit.September |
                                      MonthBit.October |
                                      MonthBit.November |
                                      MonthBit.December;

                monthDayRule.Day     = MonthDayDropDownList.SelectedIndex + 1;
                monthDayRule.Working = MonthDayWorkingCheckBox.Checked;
                m_Calendar.Rules.Add(monthDayRule);
            }

            return(m_Calendar);
        }
Ejemplo n.º 14
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set a chart title
            NLabel header = nChartControl1.Labels.AddHeader("Bollinger Bands /\n Envelopes");

            header.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            header.ContentAlignment           = ContentAlignment.BottomRight;
            header.Location = new NPointL(
                new NLength(2, NRelativeUnit.ParentPercentage),
                new NLength(2, NRelativeUnit.ParentPercentage));

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

            chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            chart.LightModel.EnableLighting         = false;
            chart.Axis(StandardAxis.Depth).Visible  = false;
            chart.Wall(ChartWallType.Floor).Visible = false;
            chart.Wall(ChartWallType.Left).Visible  = false;
            chart.BoundsMode = BoundsMode.Stretch;
            chart.Height     = 40;
            chart.Location   = new NPointL(
                new NLength(5, NRelativeUnit.ParentPercentage),
                new NLength(25, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(73, NRelativeUnit.ParentPercentage));

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

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

            linearScale.MajorGridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            linearScale.InnerMajorTickStyle.Length = new NLength(0);

            // Add line series for the upper band
            NLineSeries lineUpper = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineUpper.DataLabelStyle.Visible = false;
            lineUpper.BorderStyle.Color      = Color.Green;

            // Add line series for lower band
            NLineSeries lineLower = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineLower.DataLabelStyle.Visible = false;
            lineLower.BorderStyle.Color      = Color.Green;

            // Add line series for Simple Moving Average
            NLineSeries lineSMA = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineSMA.DataLabelStyle.Visible = false;
            lineSMA.BorderStyle.Color      = Color.Orange;
            lineSMA.Name = "Simple Moving Average";

            Color color1 = Color.FromArgb(100, 100, 150);
            Color color2 = Color.FromArgb(200, 120, 120);

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

            stock.DataLabelStyle.Visible = false;
            stock.CandleStyle            = CandleStyle.Stick;
            stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            stock.UpStrokeStyle.Color    = color1;
            stock.DownStrokeStyle.Color  = color2;
            stock.Legend.Mode            = SeriesLegendMode.None;
            stock.CloseValues.Name       = "close";
            stock.UseXValues             = true;
            stock.InflateMargins         = true;

            // Add arguments
            NFunctionCalculator upperCalculator = new NFunctionCalculator();
            NFunctionCalculator lowerCalculator = new NFunctionCalculator();
            NFunctionCalculator SMACalculator   = new NFunctionCalculator();

            upperCalculator.Arguments.Add(stock.CloseValues);
            lowerCalculator.Arguments.Add(stock.CloseValues);
            SMACalculator.Arguments.Add(stock.CloseValues);

            GenerateData(stock);

            // form controls
            if (!IsPostBack)
            {
                FunctionDropDownList.Items.Add("Bollinger Bands");
                FunctionDropDownList.Items.Add("Envelopes");
                FunctionDropDownList.SelectedIndex = 0;

                WebExamplesUtilities.FillComboWithValues(PeriodDropDownList, 0, 100, 10);
                PeriodDropDownList.SelectedIndex = 2;

                WebExamplesUtilities.FillComboWithValues(DeviationDropDownList, 0, 20, 1);
                DeviationDropDownList.SelectedIndex = 2;

                ShowPricesCheckBox.Checked = true;
                ShowSMACheckBox.Checked    = true;
            }

            UpdateExpressions(lineUpper, lineLower, upperCalculator, lowerCalculator, SMACalculator);
            CalculateFunctions(stock, lineUpper, lineLower, lineSMA, upperCalculator, lowerCalculator, SMACalculator);
            stock.Visible   = ShowPricesCheckBox.Checked;
            lineSMA.Visible = ShowSMACheckBox.Checked;
        }
Ejemplo n.º 15
0
        public override void Initialize()
        {
            base.Initialize();

            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Stick Stock Chart");

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
            title.TextStyle.FillStyle = new NColorFillStyle(GreyBlue);

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

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

            // setup X axis
            NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle            = true;
            scaleX.FirstRow.InnerTickStyle.Visible  = false;
            scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle           = true;
            scaleX.SecondRow.InnerTickStyle.Visible = false;
            scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle            = true;
            scaleX.ThirdRow.InnerTickStyle.Visible  = false;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

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

            scaleY.OuterMajorTickStyle.Length  = new NLength(3, NGraphicsUnit.Point);
            scaleY.InnerMajorTickStyle.Visible = false;

            NFillStyle       stripFill  = new NColorFillStyle(Color.FromArgb(234, 233, 237));
            NScaleStripStyle stripStyle = new NScaleStripStyle(stripFill, null, true, 1, 0, 1, 1);

            stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            stripStyle.Interlaced  = true;
            scaleY.StripStyles.Add(stripStyle);

            // add a stock series
            m_Stock                        = (NStockSeries)chart.Series.Add(SeriesType.Stock);
            m_Stock.CandleStyle            = CandleStyle.Stick;
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.UpStrokeStyle.Width    = new NLength(1, NGraphicsUnit.Point);
            m_Stock.UpStrokeStyle.Color    = Color.Black;
            m_Stock.DownStrokeStyle.Width  = new NLength(1, NGraphicsUnit.Point);
            m_Stock.DownStrokeStyle.Color  = Color.Crimson;
            m_Stock.CandleWidth            = new NLength(1.3f, NRelativeUnit.ParentPercentage);
            m_Stock.UseXValues             = true;
            m_Stock.InflateMargins         = true;

            // add some stock items
            const int count = 50;

            GenerateOHLCData(m_Stock, 100.0, count, new NRange1DD(60, 140));
            FillStockDates(m_Stock, count);

            // apply layout
            ConfigureStandardLayout(chart, title, null);

            // init form controls
            ShowHighLow.Checked = true;
            ShowOpen.Checked    = true;
            ShowClose.Checked   = true;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Called to initialize the example
        /// </summary>
        /// <param name="chartControl"></param>
        public override void Create()
        {
            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Stock Data Grouping");

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, System.Drawing.FontStyle.Italic);

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

            // setup chart
            NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];

            chart.BoundsMode = BoundsMode.Stretch;

            NRangeSelection rs = new NRangeSelection();

            rs.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
            chart.RangeSelections.Add(rs);

            // setup X axis
            NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle            = true;
            scaleX.FirstRow.InnerTickStyle.Visible  = false;
            scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle           = true;
            scaleX.SecondRow.InnerTickStyle.Visible = false;
            scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle            = true;
            scaleX.ThirdRow.InnerTickStyle.Visible  = false;

            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;

            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;
            chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;

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

            scaleY.OuterMajorTickStyle.Length  = new NLength(3, NGraphicsUnit.Point);
            scaleY.InnerMajorTickStyle.Visible = false;

            NFillStyle       stripFill  = new NColorFillStyle(Color.FromArgb(234, 233, 237));
            NScaleStripStyle stripStyle = new NScaleStripStyle(stripFill, null, true, 1, 0, 1, 1);

            stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            stripStyle.Interlaced  = true;
            scaleY.StripStyles.Add(stripStyle);

            // setup stock series
            m_Stock = (NStockSeries)chart.Series.Add(SeriesType.Stock);
            m_Stock.DataLabelStyle.Visible   = false;
            m_Stock.UpFillStyle              = new NColorFillStyle(Color.White);
            m_Stock.UpStrokeStyle.Color      = Color.Black;
            m_Stock.DownFillStyle            = new NColorFillStyle(Color.Crimson);
            m_Stock.DownStrokeStyle.Color    = Color.Crimson;
            m_Stock.HighLowStrokeStyle.Color = Color.Black;
            m_Stock.CandleWidth              = new NLength(1.2f, NRelativeUnit.ParentPercentage);
            m_Stock.UseXValues            = true;
            m_Stock.InflateMargins        = true;
            m_Stock.DataLabelStyle.Format = "open - <open>\r\nclose - <close>";

            // add some stock items
            const int numDataPoints = 10000;

            GenerateOHLCData(m_Stock, 100.0, numDataPoints, new NRange1DD(60, 140));
            FillStockDates(m_Stock, numDataPoints, DateTime.Now - new TimeSpan((int)(numDataPoints * 1.2), 0, 0, 0));

            nChartControl1.Controller.Tools.Add(new NPanelSelectorTool());
            nChartControl1.Controller.Tools.Add(new NAxisScrollTool());
            nChartControl1.Controller.Tools.Add(new NDataZoomTool());

            // apply layout
            ConfigureStandardLayout(chart, title, null);

            // update form controls
            CustomDateTimeSpanComboBox.Items.Add("1 Week");
            CustomDateTimeSpanComboBox.Items.Add("2 Weeks");
            CustomDateTimeSpanComboBox.Items.Add("1 Month");
            CustomDateTimeSpanComboBox.Items.Add("3 Months");

            NExampleHelpers.FillComboWithEnumValues(GroupingModeComboBox, typeof(StockGroupingMode));

            CustomDateTimeSpanComboBox.SelectedIndex = 2;
            GroupingModeComboBox.SelectedIndex       = (int)StockGroupingMode.AutoDateTimeSpan;
        }
Ejemplo n.º 17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            nFunction = new NFunctionCalculator();

            if (!IsPostBack)
            {
                FunctionDropDownList.Items.Add("Simple Moving Average");
                FunctionDropDownList.Items.Add("Weighted Moving Average");
                FunctionDropDownList.Items.Add("Exponential Moving Average");
                FunctionDropDownList.Items.Add("Modified Moving Average");
                FunctionDropDownList.SelectedIndex = 0;

                // form controls
                ApplyFunctionToDropDownList.Items.Add("Open");
                ApplyFunctionToDropDownList.Items.Add("High");
                ApplyFunctionToDropDownList.Items.Add("Low");
                ApplyFunctionToDropDownList.Items.Add("Close");
                ApplyFunctionToDropDownList.SelectedIndex = 3;

                WebExamplesUtilities.FillComboWithFloatValues(PeriodDropDownList, 0, 50, 1);
                PeriodDropDownList.SelectedIndex = 10;
            }

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // add header
            NLabel header = nChartControl1.Labels.AddHeader("Moving Averages");

            header.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            header.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            header.ContentAlignment           = ContentAlignment.BottomRight;
            header.Location = new NPointL(
                new NLength(2, NRelativeUnit.ParentPercentage),
                new NLength(2, NRelativeUnit.ParentPercentage));

            NLegend legend = nChartControl1.Legends[0];

            legend.Location = new NPointL(
                new NLength(98, NRelativeUnit.ParentPercentage),
                new NLength(12, NRelativeUnit.ParentPercentage));

            NChart chart = nChartControl1.Charts[0];

            chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
            chart.LightModel.EnableLighting         = false;
            chart.Axis(StandardAxis.Depth).Visible  = false;
            chart.Wall(ChartWallType.Floor).Visible = false;
            chart.Wall(ChartWallType.Left).Visible  = false;
            chart.BoundsMode = BoundsMode.Stretch;
            chart.Location   = new NPointL(
                new NLength(5, NRelativeUnit.ParentPercentage),
                new NLength(20, NRelativeUnit.ParentPercentage));
            chart.Size = new NSizeL(
                new NLength(90, NRelativeUnit.ParentPercentage),
                new NLength(75, NRelativeUnit.ParentPercentage));

            // align the chart and the legend
            NSideGuideline guideline = new NSideGuideline(PanelSide.Right);

            guideline.Targets.Add(legend);
            guideline.Targets.Add(chart);
            nChartControl1.Document.RootPanel.Guidelines.Add(guideline);

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // setup primary Y axis
            NAxis 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);

            // line series for the function
            NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);

            line.DataLabelStyle.Visible = false;
            line.BorderStyle.Color      = Color.Red;
            line.BorderStyle.Width      = new NLength(2, NGraphicsUnit.Pixel);
            line.UseXValues             = true;

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

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

            stock.DataLabelStyle.Visible   = false;
            stock.CandleStyle              = CandleStyle.Bar;
            stock.CandleWidth              = new NLength(1, NRelativeUnit.ParentPercentage);
            stock.HighLowStrokeStyle.Color = customColor;
            stock.UpStrokeStyle.Color      = customColor;
            stock.DownStrokeStyle.Color    = customColor;
            stock.UpFillStyle              = new NColorFillStyle(Color.White);
            stock.DownFillStyle            = new NColorFillStyle(customColor);
            stock.Legend.Mode              = SeriesLegendMode.None;
            stock.OpenValues.Name          = "open";
            stock.HighValues.Name          = "high";
            stock.LowValues.Name           = "low";
            stock.CloseValues.Name         = "close";
            stock.UseXValues     = true;
            stock.InflateMargins = true;

            GenerateData(stock);
            BuildExpression(stock, line);

            line.XValues = (NDataSeriesDouble)stock.XValues.Clone();
            line.Values  = nFunction.Calculate();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CandleStyleDropDownList.Items.Add("Candle");
                CandleStyleDropDownList.Items.Add("Stick");
                CandleStyleDropDownList.SelectedIndex = 0;
            }

            const int nNumberOfWeeks  = 20;
            const int nWorkDaysInWeek = 5;
            const int nTotalWorkDays  = nNumberOfWeeks * nWorkDaysInWeek;

            nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

            // set chart title
            NLabel title = nChartControl1.Labels.AddHeader("Financial Chart");

            title.TextStyle.FontStyle        = new NFontStyle("Times New Roman", 14, FontStyle.Italic);
            title.TextStyle.ShadowStyle.Type = ShadowType.LinearBlur;
            title.ContentAlignment           = ContentAlignment.BottomCenter;
            title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

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

            chart.BoundsMode = BoundsMode.Stretch;
            chart.Location   = new NPointL(new NLength(5, NRelativeUnit.ParentPercentage), new NLength(12, NRelativeUnit.ParentPercentage));
            chart.Size       = new NSizeL(new NLength(90, NRelativeUnit.ParentPercentage), new NLength(84, NRelativeUnit.ParentPercentage));
            chart.Height     = 30;

            // setup y axis
            NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;

            scaleY.MajorGridStyle.LineStyle.Pattern = LinePattern.Dot;
            scaleY.MajorGridStyle.LineStyle.Color   = Color.Gray;
            scaleY.MajorGridStyle.ShowAtWalls       = new ChartWallType[] { ChartWallType.Back };

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

            stripStyle.Interlaced  = true;
            stripStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleY.StripStyles.Add(stripStyle);

            // setup X axis
            NRangeTimelineScaleConfigurator scaleX = new NRangeTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle           = true;
            scaleX.SecondRow.GridStyle.ShowAtWalls = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle   = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle          = true;
            scaleX.ThirdRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle           = true;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            // set configurator
            chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // create a line series for the simple moving average
            NLineSeries lineSMA = (NLineSeries)chart.Series.Add(SeriesType.Line);

            lineSMA.Name = "SMA(20)";
            lineSMA.Legend.TextStyle.FontStyle.EmSize = new NLength(8, NGraphicsUnit.Point);
            lineSMA.DataLabelStyle.Visible            = false;
            lineSMA.BorderStyle.Color = Color.DarkOrange;
            lineSMA.UseXValues        = true;

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

            stock.Name                   = "Stock Data";
            stock.Legend.Mode            = SeriesLegendMode.None;
            stock.DataLabelStyle.Visible = false;
            stock.CandleStyle            = CandleStyle.Bar;
            stock.CandleWidth            = new NLength(2, NGraphicsUnit.Point);
            stock.InflateMargins         = true;
            stock.UseXValues             = true;
            stock.UpFillStyle            = new NColorFillStyle(Green);
            stock.UpStrokeStyle.Color    = Color.Black;
            stock.DownFillStyle          = new NColorFillStyle(DarkOrange);
            stock.DownStrokeStyle.Color  = Color.Black;

            // add the bollinger bands as high low area
            NHighLowSeries highLow = (NHighLowSeries)chart.Series.Add(SeriesType.HighLow);

            highLow.Name = "BB(20, 2)";
            highLow.Legend.TextStyle.FontStyle.EmSize = new NLength(8, NGraphicsUnit.Point);
            highLow.DataLabelStyle.Visible            = false;
            highLow.HighFillStyle         = new NColorFillStyle(Color.FromArgb(80, 130, 134, 168));
            highLow.HighBorderStyle.Width = new NLength(0, NGraphicsUnit.Pixel);
            highLow.UseXValues            = true;

            // generate some stock data
            WebExamplesUtilities.GenerateOHLCData(stock, 400, nTotalWorkDays + 20);
            FillStockDates(stock, nTotalWorkDays + 20);

            // create a function calculator
            NFunctionCalculator fc = new NFunctionCalculator();

            stock.CloseValues.Name = "close";
            fc.Arguments.Add(stock.CloseValues);

            // calculate the bollinger bands
            fc.Expression      = "BOLLINGER(close; 20; 2)";
            highLow.HighValues = fc.Calculate();

            fc.Expression     = "BOLLINGER(close; 20; -2)";
            highLow.LowValues = fc.Calculate();

            // calculate the simple moving average
            fc.Expression  = "SMA(close; 20)";
            lineSMA.Values = fc.Calculate();

            // remove data that won't be charted
            stock.HighValues.RemoveRange(0, 20);
            stock.LowValues.RemoveRange(0, 20);
            stock.OpenValues.RemoveRange(0, 20);
            stock.CloseValues.RemoveRange(0, 20);
            stock.XValues.RemoveRange(0, 20);

            highLow.HighValues.RemoveRange(0, 20);
            highLow.LowValues.RemoveRange(0, 20);
            highLow.XValues = (NDataSeriesDouble)stock.XValues.Clone();

            lineSMA.Values.RemoveRange(0, 20);
            lineSMA.XValues = (NDataSeriesDouble)stock.XValues.Clone();

            stock.CandleStyle = (CandleStyle)CandleStyleDropDownList.SelectedIndex;
            lineSMA.Visible   = SMACheckBox.Checked;
            highLow.Visible   = SBBCheckBox.Checked;
        }
Ejemplo n.º 19
0
        public override void Initialize()
        {
            base.Initialize();

            // set a chart title
            NLabel title = nChartControl1.Labels.AddHeader("Directional Movement");

            title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
            title.ContentAlignment    = ContentAlignment.BottomCenter;
            title.Location            = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

            // setup chart
            m_Chart            = nChartControl1.Charts[0];
            m_Chart.BoundsMode = BoundsMode.Stretch;
            m_Chart.Location   = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage), new NLength(15, NRelativeUnit.ParentPercentage));
            m_Chart.Size       = new NSizeL(new NLength(80, NRelativeUnit.ParentPercentage), new NLength(75, NRelativeUnit.ParentPercentage));

            // setup X axis
            NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();

            scaleX.FirstRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.FirstRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(225, 225, 225));
            scaleX.FirstRow.UseGridStyle            = true;
            scaleX.FirstRow.InnerTickStyle.Visible  = false;
            scaleX.SecondRow.GridStyle.ShowAtWalls  = new ChartWallType[] { ChartWallType.Back };
            scaleX.SecondRow.GridStyle.LineStyle    = new NStrokeStyle(1, Color.FromArgb(215, 215, 215));
            scaleX.SecondRow.UseGridStyle           = true;
            scaleX.SecondRow.InnerTickStyle.Visible = false;
            scaleX.ThirdRow.GridStyle.ShowAtWalls   = new ChartWallType[] { ChartWallType.Back };
            scaleX.ThirdRow.GridStyle.LineStyle     = new NStrokeStyle(1, Color.FromArgb(205, 205, 205));
            scaleX.ThirdRow.UseGridStyle            = true;
            scaleX.ThirdRow.InnerTickStyle.Visible  = false;
            // calendar
            NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);

            wdr.Saturday = false;
            wdr.Sunday   = false;
            scaleX.Calendar.Rules.Add(wdr);
            scaleX.EnableCalendar = true;
            m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

            // setup primary Y axis
            NAxis axisY1 = m_Chart.Axis(StandardAxis.PrimaryY);

            axisY1.Anchor = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 45, 100);

            NLinearScaleConfigurator scaleY1 = (NLinearScaleConfigurator)axisY1.ScaleConfigurator;

            scaleY1.RulerStyle.Height                   = new NLength(2, NGraphicsUnit.Pixel);
            scaleY1.MajorGridStyle.ShowAtWalls          = new ChartWallType[] { ChartWallType.Back };
            scaleY1.InnerMajorTickStyle.LineStyle.Width = new NLength(0);

            // setup secondary Y axis
            NAxis axisY2 = m_Chart.Axis(StandardAxis.SecondaryY);

            axisY2.Visible = true;
            axisY2.Anchor  = new NDockAxisAnchor(AxisDockZone.FrontLeft, false, 0, 40);

            NLinearScaleConfigurator scaleY2 = (NLinearScaleConfigurator)axisY2.ScaleConfigurator;

            scaleY2.RulerStyle.Height                   = new NLength(2, NGraphicsUnit.Pixel);
            scaleY2.MajorGridStyle.ShowAtWalls          = new ChartWallType[] { ChartWallType.Back };
            scaleY2.InnerMajorTickStyle.LineStyle.Width = new NLength(0);

            Color color1 = Color.FromArgb(100, 100, 150);
            Color color2 = Color.FromArgb(200, 120, 120);
            Color color3 = Color.FromArgb(100, 150, 100);

            // setup the stock series
            m_Stock = (NStockSeries)m_Chart.Series.Add(SeriesType.Stock);
            m_Stock.DataLabelStyle.Visible = false;
            m_Stock.CandleStyle            = CandleStyle.Stick;
            m_Stock.UpStrokeStyle.Color    = color1;
            m_Stock.DownStrokeStyle.Color  = color2;
            m_Stock.Legend.Mode            = SeriesLegendMode.None;
            m_Stock.CandleWidth            = new NLength(0.5f, NRelativeUnit.ParentPercentage);
            m_Stock.UseXValues             = true;
            m_Stock.InflateMargins         = true;

            // Add line series for ADX
            m_LineADX = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_LineADX.DisplayOnAxis(StandardAxis.PrimaryY, false);
            m_LineADX.DisplayOnAxis(StandardAxis.SecondaryY, true);
            m_LineADX.BorderStyle.Color = Color.LimeGreen;
            m_LineADX.Name = "ADX";
            m_LineADX.DataLabelStyle.Visible = false;
            m_LineADX.UseXValues             = true;

            // Add line series for +DI
            m_LineDIPos = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_LineDIPos.MultiLineMode = MultiLineMode.Overlapped;
            m_LineDIPos.DisplayOnAxis(StandardAxis.PrimaryY, false);
            m_LineDIPos.DisplayOnAxis(StandardAxis.SecondaryY, true);
            m_LineDIPos.BorderStyle.Color = color2;
            m_LineDIPos.Name = "+DI";
            m_LineDIPos.DataLabelStyle.Visible = false;
            m_LineDIPos.UseXValues             = true;

            // Add line series for -DI
            m_LineDINeg = (NLineSeries)m_Chart.Series.Add(SeriesType.Line);
            m_LineDINeg.MultiLineMode = MultiLineMode.Overlapped;
            m_LineDINeg.DisplayOnAxis(StandardAxis.PrimaryY, false);
            m_LineDINeg.DisplayOnAxis(StandardAxis.SecondaryY, true);
            m_LineDINeg.BorderStyle.Color = color1;
            m_LineDINeg.Name = "-DI";
            m_LineDINeg.DataLabelStyle.Visible = false;
            m_LineDINeg.UseXValues             = true;

            // add arguments for function calculator
            m_Stock.CloseValues.Name = "close";
            m_Stock.HighValues.Name  = "high";
            m_Stock.LowValues.Name   = "low";
            m_Calc.Arguments.Add(m_Stock.CloseValues);
            m_Calc.Arguments.Add(m_Stock.HighValues);
            m_Calc.Arguments.Add(m_Stock.LowValues);

            // form controls
            m_PeriodScroll.Value   = 14;
            m_ShowPosCheck.Checked = true;
            m_ShowNegCheck.Checked = true;
            m_ShowADXCheck.Checked = true;

            GenerateData();
            UpdateFunctions();
        }