public StaticStockCharts()
 {
     InitializeComponent();
     dc = new DataCollection();
     tfr = new TextFileReader();
     cs = new ChartStyle();
 }
 private void AddChart()
 {
     if (dc.DataList.Count > 0)
     {
         cs             = new ChartStyle();
         cs.ChartCanvas = chartCanvas;
         cs.TextCanvas  = textCanvas;
         cs.Xmin        = -1;
         cs.Xmax        = ds.DataString.GetLength(1);
         cs.XTick       = 3;
         cs.Ymin        = double.Parse(txYmin.Text);
         cs.Ymax        = double.Parse(txYmax.Text);
         cs.YTick       = double.Parse(txYTick.Text);
         cs.Title       = "Stock Chart";
         cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel, ds);
         dc.StockChartType = DataCollection.StockChartTypeEnum.HiLo;
         dc.AddStockChart(cs);
     }
 }
 private void AddChart()
 {
     if (dc.DataList.Count > 0)
     {
         cs = new ChartStyle();
         cs.ChartCanvas = chartCanvas;
         cs.TextCanvas = textCanvas;
         cs.Xmin = -1;
         cs.Xmax = ds.DataString.GetLength(1);
         cs.XTick = 3;
         cs.Ymin = double.Parse(txYmin.Text);
         cs.Ymax = double.Parse(txYmax.Text);
         cs.YTick = double.Parse(txYTick.Text);
         cs.Title = "Stock Chart";
         cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel, ds);
         dc.StockChartType = DataCollection.StockChartTypeEnum.HiLo;
         dc.AddStockChart(cs);
     }
 }
Example #4
0
        public void AddStockChart(ChartStyle cs)
        {
            foreach (DataSeries ds in DataList)
            {
                double barWidth = cs.ChartCanvas.Width / (5 * ds.DataString.GetLength(1));
                double d0       = cs.DateToDouble(ds.DataString[0, 0]);
                double d1       = cs.DateToDouble(ds.DataString[0, 0]);

                double[,] stockData = new double[ds.DataString.GetLength(0), ds.DataString.GetLength(1)];
                for (int i = 0; i < ds.DataString.GetLength(1); i++)
                {
                    for (int j = 1; j < stockData.GetLength(0); j++)
                    {
                        if (d0 > d1)
                        {
                            stockData[j, i] = Convert.ToDouble(ds.DataString[j, ds.DataString.GetLength(1) - 1 - i]);
                        }
                        else
                        {
                            stockData[j, i] = Convert.ToDouble(ds.DataString[j, i]);
                        }
                    }
                }
                for (int i = 0; i < ds.DataString.GetLength(1); i++)
                {
                    Point ptHigh   = cs.NormalizePoint(new Point(i - 1, stockData[4, i - 1]));
                    Point ptLow    = cs.NormalizePoint(new Point(i, stockData[3, i]));
                    Point ptOpen   = cs.NormalizePoint(new Point(i, stockData[1, i]));
                    Point ptClose  = cs.NormalizePoint(new Point(i, stockData[4, i]));
                    Point ptOpen1  = new Point(ptOpen.X - barWidth, ptOpen.Y);
                    Point ptClose1 = new Point(ptClose.X + barWidth, ptClose.Y);
                    Point ptOpen2  = new Point(ptOpen.X + barWidth, ptOpen.Y);
                    Point ptClose2 = new Point(ptClose.X - barWidth, ptClose.Y);

                    switch (StockChartType)
                    {
                    case StockChartTypeEnum.Line:
                        if (i > 0)
                        {
                            Point pt1 = cs.NormalizePoint(new Point(i - 1, stockData[4, i - 1]));
                            Point pt2 = cs.NormalizePoint(new Point(i, stockData[4, i]));
                            DrawLine(cs.ChartCanvas, pt1, pt2, ds.LineColor, ds.LineThickness);
                        }
                        break;

                    case StockChartTypeEnum.HiLo:
                        DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness);
                        break;

                    case StockChartTypeEnum.HiLoOpenClose:
                        DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness);
                        DrawLine(cs.ChartCanvas, ptOpen, ptOpen1, ds.LineColor, ds.LineThickness);
                        DrawLine(cs.ChartCanvas, ptClose, ptClose, ds.LineColor, ds.LineThickness);
                        break;

                    case StockChartTypeEnum.Candle:
                        DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness);
                        Polygon plg = new Polygon();
                        plg.Stroke          = ds.LineColor;
                        plg.StrokeThickness = ds.LineThickness;
                        Brush fillColor = ds.FillColor;
                        if (stockData[1, i] < stockData[4, i])
                        {
                            fillColor = Brushes.White;
                        }
                        plg.Fill = fillColor;
                        plg.Points.Add(ptOpen1);
                        plg.Points.Add(ptOpen2);
                        plg.Points.Add(ptClose1);
                        plg.Points.Add(ptClose2);
                        cs.ChartCanvas.Children.Add(plg);
                        break;
                    }
                }
            }
        }
Example #5
0
        public void AddStockChart(ChartStyle cs)
        {
            foreach(DataSeries ds in DataList)
            {
                double barWidth = cs.ChartCanvas.Width / (5 * ds.DataString.GetLength(1));
                double d0 = cs.DateToDouble(ds.DataString[0, 0]);
                double d1 = cs.DateToDouble(ds.DataString[0, 0]);

                double[,] stockData = new double[ds.DataString.GetLength(0), ds.DataString.GetLength(1)];
                for(int i=0; i < ds.DataString.GetLength(1); i++)
                {
                    for(int j = 1; j < stockData.GetLength(0); j++)
                    {
                        if (d0 > d1)
                            stockData[j, i] = Convert.ToDouble(ds.DataString[j, ds.DataString.GetLength(1) - 1 - i]);
                        else
                            stockData[j, i] = Convert.ToDouble(ds.DataString[j, i]);
                    }
                }
                for (int i=0; i < ds.DataString.GetLength(1); i++)
                {
                    Point ptHigh = cs.NormalizePoint(new Point(i - 1, stockData[4, i - 1]));
                    Point ptLow = cs.NormalizePoint(new Point(i, stockData[3, i]));
                    Point ptOpen = cs.NormalizePoint(new Point(i, stockData[1, i]));
                    Point ptClose = cs.NormalizePoint(new Point(i, stockData[4, i]));
                    Point ptOpen1 = new Point(ptOpen.X - barWidth, ptOpen.Y);
                    Point ptClose1 = new Point(ptClose.X + barWidth, ptClose.Y);
                    Point ptOpen2 = new Point(ptOpen.X + barWidth, ptOpen.Y);
                    Point ptClose2 = new Point(ptClose.X - barWidth, ptClose.Y);

                    switch (StockChartType)
                    {
                        case StockChartTypeEnum.Line:
                            if(i > 0)
                            {
                                Point pt1 = cs.NormalizePoint(new Point(i - 1, stockData[4, i - 1]));
                                Point pt2 = cs.NormalizePoint(new Point(i, stockData[4, i]));
                                DrawLine(cs.ChartCanvas, pt1, pt2, ds.LineColor, ds.LineThickness);
                            }
                            break;
                        case StockChartTypeEnum.HiLo:
                            DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness);
                            break;
                        case StockChartTypeEnum.HiLoOpenClose:
                            DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness);
                            DrawLine(cs.ChartCanvas, ptOpen, ptOpen1, ds.LineColor, ds.LineThickness);
                            DrawLine(cs.ChartCanvas, ptClose, ptClose, ds.LineColor, ds.LineThickness);
                            break;
                        case StockChartTypeEnum.Candle:
                            DrawLine(cs.ChartCanvas, ptLow, ptHigh, ds.LineColor, ds.LineThickness);
                            Polygon plg = new Polygon();
                            plg.Stroke = ds.LineColor;
                            plg.StrokeThickness = ds.LineThickness;
                            Brush fillColor = ds.FillColor;
                            if (stockData[1, i] < stockData[4, i])
                                fillColor = Brushes.White;
                            plg.Fill = fillColor;
                            plg.Points.Add(ptOpen1);
                            plg.Points.Add(ptOpen2);
                            plg.Points.Add(ptClose1);
                            plg.Points.Add(ptClose2);
                            cs.ChartCanvas.Children.Add(plg);
                            break;
                    }
                }
            }
        }