Example #1
0
        bool ChangeFromStockChart(SpreadChartType fromChartType, SpreadChartType toChartType)
        {
            Dt.Cells.Data.SpreadChartUtility.GetDataDimension(fromChartType);
            int dataDimension = Dt.Cells.Data.SpreadChartUtility.GetDataDimension(toChartType);

            if ((_chart.DataSeries.Count <= 0) || !(_chart.DataSeries[0] is SpreadOpenHighLowCloseSeries))
            {
                return(false);
            }
            string itemsFormula = _chart.ItemsFormula;

            ResetDataSeriesChartType();
            _chart.ChartType = toChartType;
            List <SpreadDataSeries>      list   = new List <SpreadDataSeries>();
            SpreadOpenHighLowCloseSeries series = _chart.DataSeries[0] as SpreadOpenHighLowCloseSeries;

            for (int i = 0; i < 4; i++)
            {
                SpreadDataSeries openSeries = null;
                switch (i)
                {
                case 0:
                    openSeries = series.OpenSeries;
                    break;

                case 1:
                    openSeries = series.HighSeries;
                    break;

                case 2:
                    openSeries = series.LowSeries;
                    break;

                case 3:
                    openSeries = series.CloseSeries;
                    break;
                }
                if (openSeries.Stroke == null)
                {
                    openSeries.IsAutomaticStroke = true;
                }
                MemoryStream stream = new MemoryStream();
                XmlWriter    writer = XmlWriter.Create((Stream)stream);
                if (writer != null)
                {
                    Serializer.SerializeObj(openSeries, "DataSeires", writer);
                    writer.Close();
                    stream.Seek(0L, (SeekOrigin)SeekOrigin.Begin);
                    XmlReader @this = XmlReader.Create((Stream)stream);
                    if (@this != null)
                    {
                        SpreadDataSeries series3 = Dt.Cells.Data.ChangeChartTypeHelper.CreateDataSeries(toChartType);
                        ((IXmlSerializable)series3).ReadXml(@this);
                        if (series3 is SpreadXYDataSeries)
                        {
                            SpreadXYDataSeries series4 = series3 as SpreadXYDataSeries;
                            if (!string.IsNullOrEmpty(series.XValueFormula))
                            {
                                series4.XValueFormula = series.XValueFormula;
                            }
                            else if (series.XValues.Count > 0)
                            {
                                series4.XValues = series.XValues;
                            }
                        }
                        series3.ResetChartType();
                        @this.Close();
                        list.Add(series3);
                    }
                }
            }
            if (((dataDimension == 1) && string.IsNullOrEmpty(itemsFormula)) && (itemsFormula != series.XValueFormula))
            {
                if (toChartType.ToString().ToLower().Contains("bar"))
                {
                    _chart.AxisY.ItemsFormula = series.XValueFormula;
                    _chart.AxisX.ItemsFormula = null;
                }
                else
                {
                    _chart.AxisX.ItemsFormula = series.XValueFormula;
                    _chart.AxisY.ItemsFormula = null;
                }
            }
            if (list.Count > 0)
            {
                _chart.DataSeries.Clear();
                _chart.DataSeries.AddRange((IList <SpreadDataSeries>)list);
            }
            return(true);
        }
Example #2
0
        bool ChangeToStockChart(SpreadChartType fromChartType, SpreadChartType toChartType)
        {
            Dt.Cells.Data.SpreadChartUtility.GetDataDimension(fromChartType);
            Dt.Cells.Data.SpreadChartUtility.GetDataDimension(toChartType);
            if (_chart.DataSeries.Count < 4)
            {
                return(false);
            }
            string itemsFormula = _chart.ItemsFormula;

            _chart.ChartType = toChartType;
            List <SpreadDataSeries> list        = new List <SpreadDataSeries>();
            SpreadDataSeries        openSeries  = _chart.DataSeries[0];
            SpreadDataSeries        highSeries  = _chart.DataSeries[1];
            SpreadDataSeries        lowSeries   = _chart.DataSeries[2];
            SpreadDataSeries        closeSeries = _chart.DataSeries[3];

            openSeries.Stroke  = null;
            highSeries.Stroke  = null;
            lowSeries.Stroke   = null;
            closeSeries.Stroke = null;
            SpreadOpenHighLowCloseSeries series5 = new SpreadOpenHighLowCloseSeries(openSeries, highSeries, lowSeries, closeSeries);

            if (!string.IsNullOrEmpty(itemsFormula))
            {
                series5.XValueFormula = itemsFormula;
            }
            else if (openSeries is SpreadXYDataSeries)
            {
                SpreadXYDataSeries series6 = openSeries as SpreadXYDataSeries;
                if (!string.IsNullOrEmpty(series6.XValueFormula))
                {
                    series5.XValueFormula = series6.XValueFormula;
                }
                else if (series6.XValues.Count > 0)
                {
                    series5.XValues = series6.XValues;
                }
            }
            MemoryStream stream = new MemoryStream();
            XmlWriter    writer = XmlWriter.Create((Stream)stream);

            if (writer != null)
            {
                Serializer.SerializeObj(series5, "DataSeries", writer);
                writer.Close();
                stream.Seek(0L, (SeekOrigin)SeekOrigin.Begin);
                XmlReader @this = XmlReader.Create((Stream)stream);
                if (@this != null)
                {
                    SpreadOpenHighLowCloseSeries series7 = Dt.Cells.Data.ChangeChartTypeHelper.CreateDataSeries(toChartType) as SpreadOpenHighLowCloseSeries;
                    ((IXmlSerializable)series7).ReadXml(@this);
                    @this.Close();
                    list.Add(series7);
                }
            }
            _chart.AxisX.ItemsFormula = null;
            _chart.AxisY.ItemsFormula = null;
            if (list.Count > 0)
            {
                _chart.DataSeries.Clear();
                _chart.DataSeries.AddRange((IList <SpreadDataSeries>)list);
            }
            return(true);
        }
Example #3
0
 private void AddStockChart()
 {
     SpreadOpenHighLowCloseSeries ds = new SpreadOpenHighLowCloseSeries();
     DoubleSeriesCollection dcx = new DoubleSeriesCollection();
     dcx.Add(1); dcx.Add(2); dcx.Add(3); dcx.Add(4); ds.XValues = dcx; ds.OpenSeries.Values.Add(30);
     ds.OpenSeries.Values.Add(31); ds.OpenSeries.Values.Add(32);
     ds.OpenSeries.Values.Add(33); ds.CloseSeries.Values.Add(25.45); ds.CloseSeries.Values.Add(23.05);
     ds.CloseSeries.Values.Add(17.32); ds.CloseSeries.Values.Add(20.45); ds.HighSeries.Values.Add(40);
     ds.HighSeries.Values.Add(41); ds.HighSeries.Values.Add(42);
     ds.HighSeries.Values.Add(43); ds.LowSeries.Values.Add(23.49);
     ds.LowSeries.Values.Add(19.55); ds.LowSeries.Values.Add(15.12);
     ds.LowSeries.Values.Add(17.84);
     var chart = testSpread.ActiveSheet.AddChart("chart", SpreadChartType.StockHighLowOpenClose, 50, 50, 500, 400);
     chart.DataSeries.Add(ds);
 }