Example #1
0
        public JapaneseCandleStickItem AddCandleStick(string name, double[] seriesHigh, double[] seriesLow, double[] seriesOpen, double[] seriesClose, double[] seriesVolume,
                                                      Color color, Color stickColor, Color risingColor, Color fallingColor)
        {
            if (this.mySeriesX == null)
            {
                return(null);
            }
            StockPointList spl = new StockPointList();

            for (int idx = 0; idx < this.mySeriesX.Length; idx++)
            {
                StockPt pt = new StockPt(this.mySeriesX[idx],
                                         seriesHigh[idx], seriesLow[idx], seriesOpen[idx], seriesClose[idx], seriesVolume[idx]);
                spl.Add(pt);
            }

            JapaneseCandleStickItem myCurve = myGraphPane.AddJapaneseCandleStick(name, spl);

            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color      = stickColor;

            myCurve.Color = color;

            myCurve.Stick.FallingColor     = fallingColor;
            myCurve.Stick.RisingFill.Color = risingColor;
            return(myCurve);
        }
        /// <summary>
        /// Create a new curve item
        /// </summary>
        private CurveItem CreateCurveItem(Series series)
        {
            CurveItem item = null;

            switch (series.SeriesType)
            {
            case SeriesType.Candle:
                JapaneseCandleStickItem candle = new JapaneseCandleStickItem(series.Name, new StockPointList());
                candle.Stick.IsAutoSize  = true;
                candle.Stick.Color       = Color.FromArgb(46, 56, 59);
                candle.Stick.RisingFill  = new Fill(Color.FromArgb(140, 193, 118));
                candle.Stick.FallingFill = new Fill(Color.FromArgb(184, 44, 12));
                item = candle;
                break;

            case SeriesType.Line:
                LineItem line = new LineItem(series.Name, new DateTimePointList(), Color.DarkBlue, SymbolType.None);
                item = line;
                break;

            case SeriesType.Scatter:
                LineItem scatter = new LineItem(series.Name, new DateTimePointList(), Color.Black, SymbolType.Circle);
                scatter.Line           = new Line();
                scatter.Line.IsVisible = false;
                scatter.Symbol.Size    = 10;
                scatter.Symbol.Fill    = new Fill(Color.LightGreen);
                item = scatter;
                break;
            }
            return(item);
        }
Example #3
0
        public JapaneseCandleStickDemo()
            : base("Demonstration of the Japanese Candlestick Chart Type",
                   "Japanese CandleStick Demo", DemoType.Bar)
        {
            GraphPane myPane = base.GraphPane;

            myPane.Title.Text       = "Japanese Candlestick Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl  = new StockPointList();
            Random         rand = new Random();

            // First day is jan 1st
            XDate  xDate = new XDate(2006, 1, 1);
            double open  = 50.0;

            for (int i = 0; i < 50; i++)
            {
                double x     = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi    = Math.Max(open, close) + rand.NextDouble() * 5.0;
                double low   = Math.Min(open, close) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt(x, hi, low, open, close, 100000);
                spl.Add(pt);

                open = close;
                // Advance one day
                xDate.AddDays(1.0);
                // but skip the weekends
                if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6)
                {
                    xDate.AddDays(2.0);
                }
            }

            JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("trades", spl);

            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color      = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type      = AxisType.DateAsOrdinal;
            myPane.XAxis.Scale.Min = new XDate(2006, 1, 1);

            // pretty it up a little
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
            myPane.Fill       = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f);

            base.ZedGraphControl.AxisChange();
        }
Example #4
0
        private void CreateGraph_JapaneseCandleStick(ZedGraphControl z1)
        {
            GraphPane myPane = z1.GraphPane;

            myPane.Title.Text       = "Japanese Candlestick Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl  = new StockPointList();
            Random         rand = new Random();

            // First day is feb 1st
            XDate  xDate = new XDate(2006, 2, 1);
            double open  = 50.0;

            for (int i = 0; i < 100; i++)
            {
                double x     = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi    = Math.Max(open, close) + rand.NextDouble() * 5.0;
                double low   = Math.Min(open, close) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt(x, hi, low, open, close, 100000);
                spl.Add(pt);

                open = close;
                // Advance one day
                xDate.AddDays(1.0);
                // but skip the weekends
                if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6)
                {
                    xDate.AddDays(2.0);
                }
            }

            //CandleStickItem myCurve = myPane.AddCandleStick( "trades", spl, Color.Black );
            JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("trades", spl);

            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color      = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.DateAsOrdinal;

            // pretty it up a little
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
            myPane.Fill       = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f);

            // Tell ZedGraph to calculate the axis ranges
            z1.AxisChange();
            z1.Invalidate();
        }
Example #5
0
        public JapaneseCandleStickDemo()
            : base("Demonstration of the Japanese Candlestick Chart Type",
                   "Japanese CandleStick Demo", DemoType.Bar)
        {
            GraphPane myPane = base.GraphPane;

            myPane.Title.Text       = "UER/USD(欧/日)";
            myPane.XAxis.Title.Text = "交易日期";
            myPane.YAxis.Title.Text = "价格, $¥";

            StockPointList spl  = new StockPointList();
            Random         rand = new Random();

            // First day is jan 1st
            XDate  xDate = new XDate(2002, 12, 1);
            double open  = 50.0;

            for (int i = 0; i < 50; i++)
            {
                double x     = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi    = Math.Max(open, close) + rand.NextDouble() * 5.0;
                double low   = Math.Min(open, close) - rand.NextDouble() * 3.0;

                StockPt pt = new StockPt(x, hi, low, open, close, 100);
                spl.Add(pt);
                open = close;
                xDate.AddHours(1);
                if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6)
                {
                    xDate.AddDays(1.0);
                }
            }


            JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("蜡烛线", spl);

            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color      = Color.Blue;

            myPane.XAxis.Type      = AxisType.DateAsOrdinal;
            myPane.XAxis.Scale.Min = new XDate(2006, 1, 1);

            myPane.Chart.Fill = new Fill(Color.Black, Color.LightGoldenrodYellow, 45.0f);
            myPane.Fill       = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f);

            //myPane.Chart.Fill = new Fill(Color.Black);
            //myPane.Fill = new Fill(Color.Black);

            base.ZedGraphControl.AxisChange();
        }
Example #6
0
 public static void GetRangeY(JapaneseCandleStickItem curve, int fromId, int toId, ref ValueRange yRange)
 {
     for (int idx = fromId; idx <= toId; idx++)
     {
         StockPt item = (StockPt)curve.Points[idx];
         if (item.Low < yRange.Min)
         {
             yRange.Min = item.Low;
         }
         if (item.High > yRange.Max)
         {
             yRange.Max = item.High;
         }
     }
 }
Example #7
0
        private void DrawCandleStickGraph(GraphPane myPane)
        {
            InitializeGraphPane(myPane, this.Stock.Name);
            JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("", this.SPList);

            myCurve.Stick.IsAutoSize    = true;
            myCurve.Stick.RisingFill    = new Fill(RiseColor);
            myCurve.Stick.RisingBorder  = new Border(RiseColor, 1);
            myCurve.Stick.FallingFill   = new Fill(FallColor);
            myCurve.Stick.FallingBorder = new Border(FallColor, 1);
            myCurve.Stick.Color         = RiseColor;
            myCurve.Stick.FallingColor  = FallColor;

            this.OriginalXAxisScale(myPane);
            this.AutoCandlestickAxisScale(myPane);
        }
Example #8
0
        public void LoadGraph(CurrencyPair currencyPair, IList <IMarketChartData> chartData)
        {
            GraphPane myPane = zgc1.GraphPane;

            myPane.Title.Text       = "Candlestick Chart " + currencyPair.ToString();
            myPane.XAxis.Title.Text = "Date";
            myPane.YAxis.Title.Text = "Price " + currencyPair.BaseCurrency;

            StockPointList spl  = new StockPointList();
            Random         rand = new Random();

            foreach (var data in chartData)
            {
                var    xDate = new XDate(data.Time.Year, data.Time.Month, data.Time.Day, data.Time.Hour, data.Time.Minute, data.Time.Second);
                double x     = xDate;
                double close = data.Close;
                double hi    = data.High;
                double low   = data.Low;
                double open  = data.Open;

                StockPt pt = new StockPt(x, hi, low, open, close, data.VolumeBase);
                spl.Add(pt);
            }

            JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("Price", spl);

            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color      = System.Drawing.Color.Red;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.Date;

            // pretty it up a little
            myPane.Chart.Fill = new Fill(System.Drawing.Color.WhiteSmoke, System.Drawing.Color.Gray, 45.0f);
            myPane.Fill       = new Fill(System.Drawing.Color.WhiteSmoke, System.Drawing.Color.DarkOrange);


            zgc1.AxisChange();

            zgc1.Refresh();
            zgc1.Update();
            zgc1.IsShowCursorValues = true;
            this.UpdateLayout();

            IsGraphLoaded = true;
        }
Example #9
0
        private void LoadData()
        {
            DataAccess.Libs.ClearAnalysisDataCache(myData);
            myData.LoadData();

            pricePane.myGraphObj.myOnViewportChanged   += new Charts.Controls.myGraphControl.OnViewportChanged(this.Chart_OnViewportChanged);
            volumePanel.myGraphObj.myOnViewportChanged += new Charts.Controls.myGraphControl.OnViewportChanged(this.Chart_OnViewportChanged);

            pricePane.myGraphObj.myOnPointValue   += new Charts.Controls.myGraphControl.OnPointValue(PointValueEventPrice);
            volumePanel.myGraphObj.myOnPointValue += new Charts.Controls.myGraphControl.OnPointValue(PointValueEventPrice);

            pricePane.myGraphObj.myGraphPane.CurveList.Clear();
            pricePane.myGraphObj.SetSeriesX(myData.DateTime.Values, Charts.AxisType.DateAsOrdinal);

            switch (cbChartType.myValue)
            {
            case AppTypes.ChartTypes.CandleStick:
                candleCurve = pricePane.myGraphObj.AddCandleStick(myData.DataStockCode, myData.High.Values, myData.Low.Values, myData.Open.Values, myData.Close.Values, myData.Volume.Values,
                                                                  commonClass.Settings.sysChartBarUpColor, commonClass.Settings.sysChartBarDnColor,
                                                                  commonClass.Settings.sysChartBullCandleColor, commonClass.Settings.sysChartBearCandleColor);
                break;

            case AppTypes.ChartTypes.Line:
                lineCurve = pricePane.myGraphObj.AddCurveLine(myData.DataStockCode, myData.Close.Values, SymbolType.Circle, Color.Blue, 1);
                break;

            case AppTypes.ChartTypes.Bar:
                barCurve = pricePane.myGraphObj.AddCurveBar(myData.DataStockCode, myData.Close.Values, Color.Blue, Color.Blue, 1);
                break;
            }
            pricePane.myGraphObj.SetFont(14);
            pricePane.myGraphObj.DefaultViewport();
            pricePane.myGraphObj.UpdateChart();

            volumePanel.myGraphObj.myGraphPane.CurveList.Clear();
            volumePanel.myGraphObj.SetSeriesX(myData.DateTime.Values, Charts.AxisType.DateAsOrdinal);
            barCurve = volumePanel.myGraphObj.AddCurveBar(myData.DataStockCode, myData.Volume.Values, Color.Navy, Color.Green, 1);
            volumePanel.myGraphObj.SetFont(14);
            volumePanel.myGraphObj.DefaultViewport();
            volumePanel.myGraphObj.UpdateChart();
        }
Example #10
0
        private void update()
        {
            GraphPane variablePane = this.grpGraph.GraphPane;

            variablePane.CurveList.Clear();

            variablePane.Title.Text             = this.stock.StockName;
            variablePane.XAxis.Title.Text       = "Time";
            variablePane.YAxis.Title.Text       = this.stock.StockName;
            variablePane.XAxis.Type             = AxisType.Text;
            variablePane.XAxis.Scale.TextLabels = data.Time.ToArray();

            StockPointList stockList = new StockPointList();

            for (int i = 0; i < this.data.NumberObservations; i++)
            {
                XDate   date  = new XDate(this.data.XTime[i]);
                StockPt point = new StockPt(date.XLDate, this.stock.High[i], this.stock.Low[i], this.stock.Open[i], this.stock.Close[i], this.stock.Volume[i]);
                stockList.Add(point);
            }

            JapaneseCandleStickItem candle = variablePane.AddJapaneseCandleStick(this.stock.StockName, stockList);

            candle.Stick.RisingFill  = new Fill(Color.Blue, Color.LightBlue);
            candle.Stick.FallingFill = new Fill(Color.Red, Color.IndianRed);

            candle.Stick.IsAutoSize = true;



            variablePane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245),
                                               Color.FromArgb(255, 255, 190), 90F);
            variablePane.Fill = new Fill(Color.White, Color.LightBlue, 135.0f);

            grpGraph.AxisChange();

            zedGraphToolstrip1.SetData(grpGraph, variablePane);
        }
Example #11
0
        /// <summary>
        /// 取出1分钟数据的时间,开收盘价,高低价,成交量等信息输入该图
        /// </summary>
        private void Form_Load(object sender, EventArgs e)
        {
            //画一张大图,包含价格K线和成交量
            MasterPane myPaneMaster = zedG.MasterPane;

            myPaneMaster.Title.Text = secCode;
            myPaneMaster.Title.FontSpec.FontColor = Color.Black;

            //PaneMaster里面画一张价格的小图
            GraphPane panePrice = new GraphPane(new Rectangle(10, 10, 10, 10), "Mes", " t ( h )", "Rate");

            myPaneMaster.PaneList[0] = (panePrice);
            //PaneMaster里面画一张成交量的小图
            GraphPane paneVolume = new GraphPane(new Rectangle(10, 10, 10, 10), "Mes", " t ( h )", "Rate");

            myPaneMaster.PaneList.Add(paneVolume);

            //蜡烛线例子
            //设置名称和坐标轴
            panePrice.Title.Text       = "K线图";
            panePrice.XAxis.Title.Text = "日期";
            panePrice.XAxis.Title.FontSpec.FontColor = Color.Black;
            panePrice.YAxis.Title.Text = "价格";
            panePrice.YAxis.Title.FontSpec.FontColor = Color.Black;

            //spl装载时间,价格数据
            StockPointList spl  = new StockPointList();
            Random         rand = new Random();

            //将系统时间转化为xDate时间
            XDate xStart = XDate.DateTimeToXLDate(startTime);
            XDate xEnd   = XDate.DateTimeToXLDate(endTime);

            //取Sec的分钟数据,存储于data中
            List <DateTime> tradeDays = DateUtils.GetTradeDays(startTime, endTime);

            //数据准备,取minute数据,然后再将数据进行转换为各个频率
            Dictionary <string, List <KLine> > data = new Dictionary <string, List <KLine> >();

            foreach (var tempDay in tradeDays)
            {
                var stockData = Platforms.container.Resolve <StockMinuteRepository>().fetchFromLocalCsvOrWindAndSave(secCode, tempDay);
                if (!data.ContainsKey(secCode))
                {
                    data.Add(secCode, stockData.Cast <KLine>().ToList());
                }
                else
                {
                    data[secCode].AddRange(stockData.Cast <KLine>().ToList());
                }
            }

            //定义变量存储分钟数据
            Dictionary <string, List <KLine> > minuteData = new Dictionary <string, List <KLine> >();

            foreach (var variety in data)
            {
                minuteData.Add(variety.Key, data[variety.Key]);
            }

            //定义成交量
            double[] volume = new double[minuteData[secCode].Count];
            //根据频率选择累加的时间
            switch (frequency)
            {
            //取tick数据
            case 0:
                log.Info("暂时没有tick数据");
                break;

            //1min K线
            case 1:
                for (int i = 0; i < minuteData[secCode].Count; i++)
                {
                    double timePoint = i;
                    double open      = minuteData[secCode][i].open;
                    double close     = minuteData[secCode][i].close;
                    double high      = minuteData[secCode][i].high;
                    double low       = minuteData[secCode][i].low;
                    volume[i] = minuteData[secCode][i].volume;

                    StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]);
                    spl.Add(pt);

                    // 时间加1分钟
                    xStart.AddMinutes(1.0);
                    // but skip the weekends
                    if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6)
                    {
                        xStart.AddDays(2.0);
                    }
                }
                break;

            //显示5min K线
            case 2:
                Dictionary <string, List <KLine> > minuteData5Min = new Dictionary <string, List <KLine> >();
                foreach (var variety in data)
                {
                    List <KLine> data5K = new List <KLine>();
                    data5K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 5);
                    minuteData5Min.Add(variety.Key, data5K);
                }
                for (int i = 0; i < minuteData5Min[secCode].Count; i++)
                {
                    double timePoint = i;
                    double open      = minuteData5Min[secCode][i].open;
                    double close     = minuteData5Min[secCode][i].close;
                    double high      = minuteData5Min[secCode][i].high;
                    double low       = minuteData5Min[secCode][i].low;
                    volume[i] = minuteData[secCode][i].volume;

                    StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]);
                    spl.Add(pt);

                    // 时间加5分钟
                    xStart.AddMinutes(5.0);
                    // but skip the weekends
                    if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6)
                    {
                        xStart.AddDays(2.0);
                    }
                }
                break;

            //显示15min K线
            case 3:
                Dictionary <string, List <KLine> > minuteData15Min = new Dictionary <string, List <KLine> >();
                foreach (var variety in data)
                {
                    List <KLine> data15K = new List <KLine>();
                    data15K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 15);
                    minuteData15Min.Add(variety.Key, data15K);
                }
                for (int i = 0; i < minuteData15Min[secCode].Count; i++)
                {
                    double timePoint = i;
                    double open      = minuteData15Min[secCode][i].open;
                    double close     = minuteData15Min[secCode][i].close;
                    double high      = minuteData15Min[secCode][i].high;
                    double low       = minuteData15Min[secCode][i].low;
                    volume[i] = minuteData[secCode][i].volume;

                    StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]);
                    spl.Add(pt);

                    // 时间加15分钟
                    xStart.AddMinutes(15.0);
                    // but skip the weekends
                    if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6)
                    {
                        xStart.AddDays(2.0);
                    }
                }
                break;

            //显示30min K线
            case 4:
                Dictionary <string, List <KLine> > minuteData30Min = new Dictionary <string, List <KLine> >();
                foreach (var variety in data)
                {
                    List <KLine> data30K = new List <KLine>();
                    data30K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 30);
                    minuteData30Min.Add(variety.Key, data30K);
                }
                for (int i = 0; i < minuteData30Min[secCode].Count; i++)
                {
                    double timePoint = i;
                    double open      = minuteData30Min[secCode][i].open;
                    double close     = minuteData30Min[secCode][i].close;
                    double high      = minuteData30Min[secCode][i].high;
                    double low       = minuteData30Min[secCode][i].low;
                    volume[i] = minuteData[secCode][i].volume;

                    StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]);
                    spl.Add(pt);

                    // 时间加30分钟
                    xStart.AddMinutes(30.0);
                    // but skip the weekends
                    if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6)
                    {
                        xStart.AddDays(2.0);
                    }
                }
                break;

            //显示60min K线
            case 5:
                Dictionary <string, List <KLine> > minuteData60Min = new Dictionary <string, List <KLine> >();
                foreach (var variety in data)
                {
                    List <KLine> data60K = new List <KLine>();
                    data60K = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 60);
                    minuteData60Min.Add(variety.Key, data60K);
                }
                for (int i = 0; i < minuteData60Min[secCode].Count; i++)
                {
                    double timePoint = i;
                    double open      = minuteData60Min[secCode][i].open;
                    double close     = minuteData60Min[secCode][i].close;
                    double high      = minuteData60Min[secCode][i].high;
                    double low       = minuteData60Min[secCode][i].low;
                    volume[i] = minuteData[secCode][i].volume;

                    StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]);
                    spl.Add(pt);

                    // 时间加60分钟
                    xStart.AddMinutes(60.0);
                    // but skip the weekends
                    if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6)
                    {
                        xStart.AddDays(2.0);
                    }
                }
                break;

            //显示日K线
            case 6:
                Dictionary <string, List <KLine> > minuteDataDaily = new Dictionary <string, List <KLine> >();
                foreach (var variety in data)
                {
                    List <KLine> dataDaily = new List <KLine>();
                    dataDaily = MinuteFrequencyTransferUtils.MinuteToNPeriods(minuteData[variety.Key], "Minutely", 240);
                    minuteDataDaily.Add(variety.Key, dataDaily);
                }
                for (int i = 0; i < minuteDataDaily[secCode].Count; i++)
                {
                    double timePoint = i;
                    double open      = minuteDataDaily[secCode][i].open;
                    double close     = minuteDataDaily[secCode][i].close;
                    double high      = minuteDataDaily[secCode][i].high;
                    double low       = minuteDataDaily[secCode][i].low;
                    volume[i] = minuteData[secCode][i].volume;

                    StockPt pt = new StockPt(timePoint, high, low, open, close, volume[i]);
                    spl.Add(pt);

                    // 时间加1天
                    xStart.AddDays(1.0);
                    // but skip the weekends
                    if (XDate.XLDateToDayOfWeek(xStart.XLDate) == 6)
                    {
                        xStart.AddDays(2.0);
                    }
                }
                break;
            }

            //添加栅格线
            //myPane.XAxis.MajorGrid.IsVisible = true;
            //myPane.YAxis.MajorGrid.IsVisible = true;
            //myPane.XAxis.MajorGrid.Color = Color.LightGray;
            //myPane.YAxis.MajorGrid.Color = Color.LightGray;
            //myPane.YAxis.MajorGrid.DashOff = 0;
            //myPane.XAxis.MajorGrid.DashOff = 0;


            panePrice.XAxis.Type         = AxisType.Date;
            panePrice.XAxis.Scale.Format = "MM-dd";
            //myPane.XAxis.Scale.FontSpec.Angle = 45;//X轴文字方向,0-90度
            //开始Y轴坐标设置
            ////设置Y轴坐标的范围
            //myPane.YAxis.Scale.Max = Math.Round(maxhi * 1.2, 2);//Math.Ceiling(maxhi);
            //myPane.YAxis.Scale.Min = Math.Round(minlow * 0.8, 2);

            //Y轴最大刻度,注意minStep只会显示刻度线不会显示刻度值,minStep为纵坐标步长
            panePrice.YAxis.Scale.MajorStep = 0.01;

            //myPane.XAxis.Scale.FontSpec.FontColor = Color.Black;
            //myPane.YAxis.Scale.FontSpec.FontColor = Color.Black;

            panePrice.XAxis.Type = AxisType.DateAsOrdinal;
            //myPane.Legend.FontSpec.Size = 18f;
            //myPane.Legend.Position = LegendPos.InsideTopRight;
            //myPane.Legend.Location = new Location(0.5f, 0.6f, CoordType.PaneFraction,
            //    AlignH.Right, AlignV.Top);
            JapaneseCandleStickItem myCurve = panePrice.AddJapaneseCandleStick(secCode, spl);

            myCurve.Stick.IsAutoSize = true;
            //myCurve.Stick.Color = Color.Blue;
            myCurve.Stick.FallingFill = new Fill(Color.Green); //下跌颜色
            myCurve.Stick.RisingFill  = new Fill(Color.Red);   //上扬颜色

            // pretty it up a little
            //myPane.Chart.Fill = new Fill(Color.LightBlue, Color.LightGoldenrodYellow, 135.0f);
            //myPane.Fill = new Fill(Color.Orange, Color.FromArgb(220, 220, 255), 45.0f);
            Color c1 = ColorTranslator.FromHtml("#ffffff");
            Color c2 = ColorTranslator.FromHtml("#ffd693");

            panePrice.Chart.Fill = new Fill(c1); //图形区域颜色
            panePrice.Fill       = new Fill(c2); //整体颜色


            //成交量线例子
            // Set the Titles
            paneVolume.Title.Text       = "成交量";
            paneVolume.XAxis.Title.Text = "Time";
            paneVolume.YAxis.Title.Text = "Volume Num";

            // Make up some random data points
            //string[] labels = { "Panther", "Lion", "Cheetah","Cougar", "Tiger", "Leopard" };

            //double[] y1 = { 100, 115, 75, 22, 98, 40, -100, -20 };
            //double[] y2 = { 90, 100, 95, 35, 80, 35 };
            //double[] y3 = { 80, 110, 65, 15, 54, 67 };
            //double[] y4 = { 120, 125, 100, 40, 105, 75 };

            // Generate a red bar with "Curve 1" in the legend
            BarItem myBar = paneVolume.AddBar(null, null, volume, Color.Red);

            //myBar.Bar.Fill = new Fill(Color.Red);

            // Generate a blue bar with "Curve 2" in the legend
            //myBar = paneVolume.AddBar("Curve 2", null, y2, Color.Blue);
            //myBar.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue);
            //设置bar宽度
            paneVolume.BarSettings.ClusterScaleWidth = 0.5;
            log.Info(paneVolume.BarSettings.GetClusterWidth());
            paneVolume.BarSettings.Type = BarType.Cluster;

            // Generate a green bar with "Curve 3" in the legend
            //myBar = myPane.AddBar("Curve 3", null, y3, Color.Green);
            //myBar.Bar.Fill = new Fill(Color.Green, Color.White,
            // Color.Green);

            // Generate a black line with "Curve 4" in the legend
            //LineItem myCurve = myPane.AddCurve("Curve 4",
            //null, y4, Color.Black, SymbolType.Circle);
            //myCurve.Line.Fill = new Fill(Color.White,
            //Color.LightSkyBlue, -45F);

            // Fix up the curve attributes a little
            //myCurve.Symbol.Size = 8.0F;
            //myCurve.Symbol.Fill = new Fill(Color.White);
            //myCurve.Line.Width = 2.0F;

            // Draw the X tics between the labels instead of
            // at the labels
            paneVolume.XAxis.MajorTic.IsBetweenLabels = true;

            // Set the XAxis labels
            //myPane.XAxis.Scale.TextLabels = labels;
            // Set the XAxis to Text type
            paneVolume.XAxis.Type = AxisType.Text;

            // Fill the Axis and Pane backgrounds
            paneVolume.Chart.Fill = new Fill(Color.White,
                                             Color.FromArgb(255, 255, 166), 90F);
            paneVolume.Fill = new Fill(Color.FromArgb(250, 250, 255));

            using (Graphics g = CreateGraphics())
                myPaneMaster.SetLayout(g, 2, 0);
            zedG.AxisChange();
        }
Example #12
0
        public void UpdateHistoryGraphCurves()
        {
            GraphPane pane = historyGraph.GraphPane;

            // get rows
            DataRow[] rows = hs.HistoryTable.Select("", "Date ASC");
            if (rows.Length <= 0)
            {
                return;
            }

            // start date
            DateTime d0 = (DateTime)(rows[0]["Date"]);
            DateTime d1 = d0;

            history_x = new double[rows.Length];
            history_y = new double[rows.Length];

            // build points list
            StockPointList spl = new StockPointList();

            for (int i = 0; i < rows.Length; i++)
            {
                double close_adj = (double)(rows[i]["AdjClose"]);
                double close     = (double)(rows[i]["Close"]);
                double factor    = close_adj / close;
                double open      = (double)(rows[i]["Open"]) * factor;
                double low       = (double)(rows[i]["Low"]) * factor;
                double high      = (double)(rows[i]["High"]) * factor;
                double volume    = (double)(rows[i]["Volume"]);

                d1 = (DateTime)(rows[i]["Date"]);
                XDate date = new XDate(d1.Year, d1.Month, d1.Day);

                StockPt pt = new StockPt(date.XLDate, high, low, open, close_adj, volume);
                spl.Add(pt);

                history_x[i] = date.XLDate;
                history_y[i] = close_adj;
            }

            // period (maximum 6-months)
            if (d0 < d1.AddMonths(-6))
            {
                d0 = d1.AddMonths(-6);
            }
            history_xaxis_prd = (5.0 / 7.0) * ((new XDate(d1.Year, d1.Month, d1.Day)).XLDate - (new XDate(d0.Year, d0.Month, d0.Day)).XLDate);

            // x-axis
            pane.XAxis.Type                = AxisType.DateAsOrdinal;
            pane.XAxis.Scale.FormatAuto    = false;
            pane.XAxis.Scale.Format        = "dd-MMM-yy";
            pane.XAxis.Scale.MinAuto       = false;
            pane.XAxis.Scale.MaxAuto       = false;
            pane.XAxis.Scale.Min           = rows.Length - history_xaxis_prd;
            pane.XAxis.Scale.Max           = rows.Length;
            pane.XAxis.Scale.MinorStepAuto = true;
            pane.XAxis.Scale.MajorStepAuto = true;

            // y-axis
            pane.YAxis.Scale.MinAuto       = true;
            pane.YAxis.Scale.MinorStepAuto = true;
            pane.YAxis.Scale.MaxAuto       = true;
            pane.YAxis.Scale.MajorStepAuto = true;

            history_jcurve                          = pane.AddJapaneseCandleStick("", spl);
            history_jcurve.Stick.Color              = Config.Color.GraphCurveForeColor(0);
            history_jcurve.Stick.RisingFill         = new Fill(Config.Color.PositiveForeColor);
            history_jcurve.Stick.RisingBorder       = new Border(Config.Color.PositiveForeColor, 1);
            history_jcurve.Stick.FallingFill        = new Fill(Config.Color.NegativeForeColor);
            history_jcurve.Stick.FallingBorder      = new Border(Config.Color.NegativeForeColor, 1);
            history_jcurve.Label.IsVisible          = false;
            history_jcurve.Stick.IsAutoSize         = true;
            history_jcurve.Stick.IsOpenCloseVisible = true;
            history_jcurve.Stick.Width              = 1.5F; //PenWidth

            history_vcurve = pane.AddCurve("", history_x, history_y, Config.Color.GraphCurveForeColor(0), SymbolType.None);
            history_vcurve.Line.IsAntiAlias = true;
            history_vcurve.Line.IsSmooth    = false;
            history_vcurve.Line.Width       = 1;
            history_vcurve.IsVisible        = true;
            history_vcurve.Label.IsVisible  = false;

            historyGraph.AxisChange();
            historyGraph.Invalidate();

            // update graph default axis
            history_xaxis_min = pane.XAxis.Scale.Min;
            history_xaxis_max = pane.XAxis.Scale.Max;
            history_xaxis_maj = pane.XAxis.Scale.MajorStep;
            history_xaxis_mor = pane.XAxis.Scale.MinorStep;
            history_yaxis_min = pane.YAxis.Scale.Min;
            history_yaxis_max = pane.YAxis.Scale.Max;
            history_yaxis_maj = pane.YAxis.Scale.MajorStep;
            history_yaxis_mor = pane.YAxis.Scale.MinorStep;

            // add history cursor curves
            AddHistoryCursorCurves();
        }