Beispiel #1
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();
        }
Beispiel #2
0
        public FinancialDemo()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            costPS.Clear();

            // obtain stock information from xml file
            DataSet ds = new DataSet();

            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("SwfTest.Resources.asx_jbh.xml");
            ds.ReadXml(file, System.Data.XmlReadMode.ReadSchema);
            DataTable dt = ds.Tables[0];
            //DataView dv = new DataView(dt);

            // create CandlePlot.
            CandlePlot cp = new CandlePlot();

            cp.DataSource        = dt;
            cp.AbscissaData      = "Date";
            cp.OpenData          = "Open";
            cp.LowData           = "Low";
            cp.HighData          = "High";
            cp.CloseData         = "Close";
            cp.BearishColor      = Color.Red;
            cp.BullishColor      = Color.Green;
            cp.Style             = CandlePlot.Styles.Filled;
            costPS.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            costPS.Add(new Grid());
            costPS.Add(cp);
            costPS.Title                      = "AU:JBH";
            costPS.YAxis1.Label               = "Price [$]";
            costPS.YAxis1.LabelOffset         = 40;
            costPS.YAxis1.LabelOffsetAbsolute = true;
            costPS.XAxis1.HideTickText        = true;
            costPS.SurfacePadding             = 5;

            costPS.AddInteraction(new NPlot.PlotDrag(true, true));
            costPS.AddInteraction(new NPlot.AxisDrag());
            costPS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(costPS_InteractionOccurred);
            costPS.AddAxesConstraint(new AxesConstraint.Position(YAxisPosition.Left, 60));

            costPS.Refresh();


            PointPlot pp = new PointPlot();

            pp.Marker          = new Marker(Marker.MarkerType.Square, 0);
            pp.Marker.Pen      = new Pen(Color.Red, 5.0f);
            pp.Marker.DropLine = true;
            pp.DataSource      = dt;
            pp.AbscissaData    = "Date";
            pp.OrdinateData    = "Volume";
            volumePS.Add(pp);
            volumePS.YAxis1.Label = "Volume";
            volumePS.YAxis1.LabelOffsetAbsolute = true;
            volumePS.YAxis1.LabelOffset         = 40;
            volumePS.SurfacePadding             = 5;


            volumePS.AddAxesConstraint(new AxesConstraint.Position(YAxisPosition.Left, 60));
            volumePS.AddInteraction(new NPlot.AxisDrag());
            volumePS.AddInteraction(new NPlot.PlotDrag(true, false));
            volumePS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(volumePS_InteractionOccurred);
            volumePS.PreRefresh          += new NPlot.InteractivePlotSurface2D.PreRefreshHandler(volumePS_PreRefresh);

            volumePS.Refresh();
        }