Beispiel #1
0
        private void DrawAxisTests(Context ctx, Rectangle bounds)
        {
            Rectangle boundingBox;
            Point     tl = Point.Zero;
            Point     br = Point.Zero;

            tl.X = bounds.Left + 30;        tl.Y = bounds.Top + 20;
            br.X = bounds.Right - 30;       br.Y = bounds.Top + 20;

            DateTime timeMin = new DateTime(2003, 10, 22, 15, 00, 00);
            DateTime timeMax = new DateTime(2004, 03, 12, 13, 30, 00);

            TradingDateTimeAxis axis = new TradingDateTimeAxis();

            axis.WorldMin = (double)timeMin.Ticks;
            axis.WorldMax = (double)timeMax.Ticks;
            axis.Draw(ctx, tl, br, out boundingBox);

            timeMin       = new DateTime(2013, 09, 17, 12, 30, 10);
            timeMax       = new DateTime(2014, 01, 23, 12, 59, 30);
            axis.WorldMin = (double)timeMin.Ticks;
            axis.WorldMax = (double)timeMax.Ticks;

            tl.Y += 50;             br.Y += 50;
            axis.Draw(ctx, tl, br, out boundingBox);
        }
Beispiel #2
0
        public StockChartBasic(string symbol)
        {
            this.Symbol = symbol;
            DataTable emptyTable = new DataTable();

            emptyTable.Columns.Add("Time", typeof(DateTime));
            emptyTable.Columns.Add("Price", typeof(float));

            // Create the price line for the plot
            priceLine              = new LinePlot();
            priceLine.DataSource   = emptyTable;
            priceLine.AbscissaData = TIME_DATA_TAG;
            priceLine.OrdinateData = PRICE_DATA_TAG;
            priceLine.Color        = GuiStyle.PRICE_COLOR_POSITIVE;

            // Create the origin open price line
            openLine                 = new LinePlot();
            openLine.DataSource      = emptyTable;
            openLine.AbscissaData    = TIME_DATA_TAG;
            openLine.OrdinateData    = PRICE_DATA_TAG;
            openLine.Pen             = new System.Drawing.Pen(GuiStyle.GUIDE_COLOR);
            openLine.Pen.DashPattern = new float[] { 2.0f, 2.0f };
            openLine.Pen.DashCap     = System.Drawing.Drawing2D.DashCap.Round;
            openLine.Pen.Width       = 1.5f;

            // Create the surface used to draw the plot
            stockPricePlot = new NPlot.Swf.InteractivePlotSurface2D();
            stockPricePlot.SurfacePadding = 0;
            stockPricePlot.Add(priceLine);
            stockPricePlot.Add(openLine);
            stockPricePlot.SmoothingMode       = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            stockPricePlot.ShowCoordinates     = false;
            stockPricePlot.XAxis1.HideTickText = true;
            //stockPricePlot.XAxis1.NumberFormat = " h";
            stockPricePlot.XAxis1.AxisColor = System.Drawing.Color.Transparent;
            TradingDateTimeAxis tradeAxis = new TradingDateTimeAxis(stockPricePlot.XAxis1);

            tradeAxis.StartTradingTime           = new TimeSpan(9, 30, 0);
            tradeAxis.EndTradingTime             = new TimeSpan(16, 0, 0);
            stockPricePlot.XAxis1                = tradeAxis;
            stockPricePlot.YAxis1.HideTickText   = true;
            stockPricePlot.YAxis1.Color          = System.Drawing.Color.Transparent;
            stockPricePlot.PlotBackColor         = GuiStyle.BACKGROUND_COLOR;
            stockPricePlot.Canvas.HandleCreated += (sender, e) =>
            {
                stockPricePlot.Canvas.BackColor = stockPricePlot.Canvas.Parent.BackColor;
                //SetChartData(Source);
            };

            stockPricePlot.Refresh();
        }
Beispiel #3
0
        /// <summary>
        /// Sets the data for the chart to use
        /// </summary>
        /// <param name="data">A table of data which contains Time and Price columns</param>
        public void SetChartData(DataTable data)
        {
            TradingDateTimeAxis tradeAxis = (TradingDateTimeAxis)stockPricePlot.XAxis1;

            this.Source          = data;
            priceLine.DataSource = Source;

            // Set the initial view of the data to the last trading day
            tradeAxis.WorldMax = (double)((DateTime)data.Rows[data.Rows.Count - 1][TIME_DATA_TAG]).Date.Ticks;
            tradeAxis.WorldMin = (double)((DateTime)data.Rows[data.Rows.Count - 1][TIME_DATA_TAG]).Date.AddHours(-12).Ticks;

            // Create a data table which acts as a reference point for each day
            DailyData = new DataTable();
            DailyData.Columns.Add("Time", typeof(DateTime));
            DailyData.Columns.Add("Price", typeof(float));
            DailyData.Columns.Add("Min", typeof(float));
            DailyData.Columns.Add("Max", typeof(float));
            float dayPrice = (float)data.Rows[0][PRICE_DATA_TAG];

            for (DateTime time = ((DateTime)data.Rows[0][TIME_DATA_TAG]).Date.AddHours(16); time <= ((DateTime)data.Rows[data.Rows.Count - 1][TIME_DATA_TAG]).Date.AddHours(16); time = time.AddDays(1))
            {
                int idx = GetTimeIndex(time);
                if (((DateTime)data.Rows[idx][TIME_DATA_TAG]).Date == time.Date)
                {
                    // Mark the time as the last trading time for the next day
                    DailyData.Rows.Add(time.Date.AddHours(9.5), dayPrice, 0, 0);
                    DailyData.Rows.Add(time.Date.AddHours(16), dayPrice, 0, 0);

                    // Set the ending price of this day as the reference point of the next day
                    dayPrice = (float)data.Rows[idx][PRICE_DATA_TAG];
                }
            }
            openLine.DataSource = DailyData;

            // Update the price text
            priceText.Text = string.Format("{0:c}", (float)Source.Rows[Source.Rows.Count - 1][PRICE_DATA_TAG]);

            // Refresh the chart
            UpdatePriceMinMax();
            stockPricePlot.Refresh();
        }
Beispiel #4
0
        /// <summary>
        /// Updates and re-draws the chart based on the current data set
        /// </summary>
        protected virtual void UpdateChartData()
        {
            if (priceLine.DataSource != Source)
            {
                TradingDateTimeAxis tradeAxis = (TradingDateTimeAxis)stockPricePlot.XAxis1;
                priceLine.DataSource = Source;

                // Set the initial view of the data to the last trading day
                tradeAxis.WorldMax = (double)((DateTime)Source.Rows[Source.Rows.Count - 1][TIME_DATA_TAG]).Date.AddHours(16).Ticks;
                tradeAxis.WorldMin = tradeAxis.SparseWorldAdd((double)(new DateTime((long)tradeAxis.WorldMax)).Ticks, -(tradeAxis.EndTradingTime - tradeAxis.StartTradingTime).Ticks * 1.5);

                // Create a data table which acts as a reference point for each day
                DailyData = new DataTable();
                DailyData.Columns.Add("Time", typeof(DateTime));
                DailyData.Columns.Add("Price", typeof(float));
                DailyData.Columns.Add("Min", typeof(float));
                DailyData.Columns.Add("Max", typeof(float));
                float dayPrice = (float)Source.Rows[0][PRICE_DATA_TAG];
                for (DateTime time = ((DateTime)Source.Rows[0][TIME_DATA_TAG]).Date.AddHours(16); time <= ((DateTime)Source.Rows[Source.Rows.Count - 1][TIME_DATA_TAG]).Date.AddHours(16); time = time.AddDays(1))
                {
                    int idx = GetTimeIndex(time);
                    if (((DateTime)Source.Rows[idx][TIME_DATA_TAG]).Date == time.Date)
                    {
                        // Mark the time as the last trading time for the next day
                        DailyData.Rows.Add(time.Date.AddHours(9.5), dayPrice, 0, 0);
                        DailyData.Rows.Add(time.Date.AddHours(16), dayPrice, 0, 0);

                        // Set the ending price of this day as the reference point of the next day
                        dayPrice = (float)Source.Rows[idx][PRICE_DATA_TAG];
                    }
                }
                openLine.DataSource = DailyData;
            }

            // Refresh the chart
            UpdatePriceMinMax();
            stockPricePlot.Refresh();
        }
Beispiel #5
0
        public StockChart()
        {
            DataTable emptyTable = new DataTable();

            emptyTable.Columns.Add("Time", typeof(DateTime));
            emptyTable.Columns.Add("Price", typeof(float));

            // Create the price line for the plot
            priceLine              = new LinePlot();
            priceLine.DataSource   = emptyTable;
            priceLine.AbscissaData = TIME_DATA_TAG;
            priceLine.OrdinateData = PRICE_DATA_TAG;
            priceLine.Color        = PRICE_COLOR_POSITIVE;

            // Create the origin open price line
            openLine                 = new LinePlot();
            openLine.DataSource      = emptyTable;
            openLine.AbscissaData    = TIME_DATA_TAG;
            openLine.OrdinateData    = PRICE_DATA_TAG;
            openLine.Pen             = new System.Drawing.Pen(GUIDE_COLOR);
            openLine.Pen.DashPattern = new float[] { 2.0f, 2.0f };
            openLine.Pen.DashCap     = System.Drawing.Drawing2D.DashCap.Round;
            openLine.Pen.Width       = 1.5f;

            // Create the surface used to draw the plot
            stockPricePlot = new NPlot.Swf.InteractivePlotSurface2D();
            stockPricePlot.Add(priceLine);
            stockPricePlot.Add(openLine);
            stockPricePlot.SmoothingMode             = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            stockPricePlot.ShowCoordinates           = false;
            stockPricePlot.XAxis1.TicksCrossAxis     = false;
            stockPricePlot.XAxis1.TickTextNextToAxis = true;
            stockPricePlot.XAxis1.SmallTickSize      = 0;
            stockPricePlot.XAxis1.LargeTickSize      = 0;
            stockPricePlot.XAxis1.HideTickText       = false;
            //stockPricePlot.XAxis1.NumberFormat = " h";
            stockPricePlot.XAxis1.TickTextColor   = openLine.Pen.Color;
            stockPricePlot.XAxis1.TickTextFont    = new System.Drawing.Font("monospace", 8.0f, System.Drawing.FontStyle.Bold);
            stockPricePlot.XAxis1.AxisColor       = System.Drawing.Color.Transparent;
            stockPricePlot.XAxis1.TicksLabelAngle = (float)0;
            TradingDateTimeAxis tradeAxis = new TradingDateTimeAxis(stockPricePlot.XAxis1);

            tradeAxis.StartTradingTime               = new TimeSpan(9, 30, 0);
            tradeAxis.EndTradingTime                 = new TimeSpan(16, 0, 0);
            stockPricePlot.XAxis1                    = tradeAxis;
            stockPricePlot.YAxis1.HideTickText       = false;
            stockPricePlot.YAxis1.Color              = System.Drawing.Color.Transparent;
            stockPricePlot.YAxis1.TickTextNextToAxis = true;
            stockPricePlot.YAxis1.TicksIndependentOfPhysicalExtent = true;
            stockPricePlot.YAxis1.TickTextColor = openLine.Pen.Color;
            stockPricePlot.PlotBackColor        = BACKGROUND_COLOR;
            stockPricePlot.SurfacePadding       = 5;

            // Create the interaction for the chart
            stockPricePlot.AddInteraction(new PlotDrag(true, false));
            stockPricePlot.AddInteraction(new AxisDrag());
            stockPricePlot.AddInteraction(new HoverInteraction(this));

            // Create the text controls
            priceText           = new Label();
            priceText.Location  = new System.Drawing.Point((stockPricePlot.Canvas.Width - 100) / 2, 10);
            priceText.Font      = new System.Drawing.Font("monoprice", 12.0f, System.Drawing.FontStyle.Regular);
            priceText.ForeColor = System.Drawing.Color.White;
            priceText.BackColor = System.Drawing.Color.Transparent;
            priceText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            stockPricePlot.Canvas.Controls.Add(priceText);
            priceText.BringToFront();

            stockPricePlot.Refresh();
        }