예제 #1
0
파일: DataPoint.cs 프로젝트: Daoting/dt
 internal DataPoint(SpreadDataSeries dataSeries, int pointIndex) : base(dataSeries.Chart)
 {
     this._isBubble3D = true;
     this.Init();
     this._dataSeries = dataSeries;
     this._pointIndex = pointIndex;
 }
예제 #2
0
 internal override void Init()
 {
     base.Init();
     this._highSeries            = new SpreadDataSeries();
     this._highSeries.MarkerType = MarkerType.None;
     this._highSeries.Stroke     = null;
     this._lowSeries             = new SpreadDataSeries();
     this._lowSeries.MarkerType  = MarkerType.None;
     this._lowSeries.Stroke      = null;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Dt.Cells.Data.SpreadHighLowSeries" /> class.
 /// </summary>
 /// <param name="highSeries">The high series.</param>
 /// <param name="lowSeris">The low series.</param>
 public SpreadHighLowSeries(SpreadDataSeries highSeries, SpreadDataSeries lowSeris)
 {
     this.Init();
     this._highSeries            = highSeries;
     this._lowSeries             = lowSeris;
     this._highSeries.MarkerType = MarkerType.None;
     this._highSeries.Stroke     = null;
     this._lowSeries.MarkerType  = MarkerType.None;
     this._lowSeries.Stroke      = null;
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Dt.Cells.Data.SpreadOpenHighLowCloseSeries" /> class.
 /// </summary>
 /// <param name="openSeries">The open series.</param>
 /// <param name="highSeries">The high series.</param>
 /// <param name="lowSeries">The low series.</param>
 /// <param name="closeSeries">The close series.</param>
 public SpreadOpenHighLowCloseSeries(SpreadDataSeries openSeries, SpreadDataSeries highSeries, SpreadDataSeries lowSeries, SpreadDataSeries closeSeries) : base(highSeries, lowSeries)
 {
     this._openSeries             = openSeries;
     this._closeSeries            = closeSeries;
     this._openSeries.MarkerType  = MarkerType.None;
     this._openSeries.Stroke      = null;
     this._closeSeries.MarkerType = MarkerType.None;
     this._closeSeries.Stroke     = null;
     this._isOpenEmpty            = false;
 }
예제 #5
0
        bool ChangeChartTypeOne(SpreadChartType fromChartType, SpreadChartType toChartType)
        {
            SpreadChartUtility.GetDataDimension(fromChartType);
            SpreadChartUtility.GetDataDimension(toChartType);
            string itemsFormula  = _chart.ItemsFormula;
            string xValueFormula = null;

            _chart.ChartType = toChartType;
            ResetDataSeriesChartType();
            List <SpreadDataSeries> list = new List <SpreadDataSeries>();

            foreach (SpreadDataSeries series in _chart.DataSeries)
            {
                MemoryStream stream = new MemoryStream();
                XmlWriter    writer = XmlWriter.Create((Stream)stream);
                if (writer != null)
                {
                    Serializer.SerializeObj(series, "DataSeries", writer);
                    writer.Close();
                    stream.Seek(0L, (SeekOrigin)SeekOrigin.Begin);
                    XmlReader @this = XmlReader.Create((Stream)stream);
                    if (@this != null)
                    {
                        SpreadDataSeries series2 = Dt.Cells.Data.ChangeChartTypeHelper.CreateDataSeries(toChartType);
                        ((IXmlSerializable)series2).ReadXml(@this);
                        if (string.IsNullOrEmpty(xValueFormula) && (series is SpreadXYDataSeries))
                        {
                            xValueFormula = (series as SpreadXYDataSeries).XValueFormula;
                        }
                        series2.ResetChartType();
                        @this.Close();
                        list.Add(series2);
                    }
                }
            }
            if (string.IsNullOrEmpty(itemsFormula) && (itemsFormula != xValueFormula))
            {
                if (toChartType.ToString().ToLower().Contains("bar"))
                {
                    _chart.AxisY.ItemsFormula = xValueFormula;
                    _chart.AxisX.ItemsFormula = null;
                }
                else
                {
                    _chart.AxisX.ItemsFormula = xValueFormula;
                    _chart.AxisY.ItemsFormula = null;
                }
            }
            if (list.Count > 0)
            {
                _chart.DataSeries.Clear();
                _chart.DataSeries.AddRange((IList <SpreadDataSeries>)list);
            }
            return(true);
        }
예제 #6
0
 internal override void Init()
 {
     base.Init();
     this._openSeries             = new SpreadDataSeries();
     this._openSeries.MarkerType  = MarkerType.None;
     this._openSeries.Stroke      = null;
     this._closeSeries            = new SpreadDataSeries();
     this._closeSeries.MarkerType = MarkerType.None;
     this._closeSeries.Stroke     = null;
     this._isOpenEmpty            = false;
 }
예제 #7
0
 public static int GetDataDimension(SpreadDataSeries dataSereis)
 {
     if (dataSereis.GetType() == typeof(SpreadDataSeries))
     {
         return(1);
     }
     if (dataSereis.GetType() == typeof(SpreadXYDataSeries))
     {
         return(2);
     }
     if ((dataSereis.GetType() == typeof(SpreadBubbleSeries)) || (dataSereis.GetType() == typeof(SpreadXYZDataSeries)))
     {
         return(3);
     }
     if (dataSereis.GetType() == typeof(SpreadOpenHighLowCloseSeries))
     {
         return(5);
     }
     return(GetDataDimension(dataSereis.ChartType));
 }
예제 #8
0
 internal override void AfterReadXml()
 {
     base.AfterReadXml();
     if (this._highSeries != null)
     {
         this._highSeries.Chart = base.Chart;
     }
     else
     {
         this._highSeries = new SpreadDataSeries();
     }
     if (this._lowSeries != null)
     {
         this._lowSeries.Chart = base.Chart;
     }
     else
     {
         this._lowSeries = new SpreadDataSeries();
     }
 }
예제 #9
0
        internal override void ReadXmlInternal(XmlReader reader)
        {
            string str;

            base.ReadXmlInternal(reader);
            if ((reader.NodeType == ((XmlNodeType)((int)XmlNodeType.Element))) && ((str = reader.Name) != null))
            {
                if (str != "OpenSeries")
                {
                    if (str != "CloseSeries")
                    {
                        return;
                    }
                }
                else
                {
                    this._openSeries = (SpreadDataSeries)Serializer.DeserializeObj(typeof(SpreadDataSeries), reader);
                    return;
                }
                this._closeSeries = (SpreadDataSeries)Serializer.DeserializeObj(typeof(SpreadDataSeries), reader);
            }
        }
예제 #10
0
 internal OpenHighLowCloseDataPoint(SpreadDataSeries dataSeries, SpreadOpenHighLowCloseSeries openHighLowCloseSeries, int pointIndex) : base(dataSeries, pointIndex)
 {
     this._openHighLowCloseSeries = openHighLowCloseSeries;
 }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
0
파일: DataPoint.cs 프로젝트: Daoting/dt
 internal void SetParentSeriesInternal(SpreadDataSeries series)
 {
     this._dataSeries = series;
     this.SetChartInternal(series.Chart);
 }
예제 #14
0
파일: RptChart.cs 프로젝트: Daoting/dt
        /// <summary>
        /// 输出图表
        /// </summary>
        /// <param name="p_ws"></param>
        /// <param name="p_row"></param>
        /// <param name="p_col"></param>
        public void Render(Worksheet p_ws, int p_row, int p_col)
        {
            if (!ValidFilds())
            {
                return;
            }

            Rect        rc        = p_ws.GetRangeLocation(new CellRange(p_row, p_col, RowSpan, ColSpan));
            var         chartType = GetChartType();
            SpreadChart c         = p_ws.AddChart("chart" + p_ws.Charts.Count.ToString(), chartType, rc.Left, rc.Top, rc.Width, rc.Height);

            // 锁定图表,禁止拖动缩放
            c.Locked = true;

            string title = _data.Str("title");

            if (!string.IsNullOrEmpty(title))
            {
                c.ChartTitle = new ChartTitle {
                    Text = title
                }
            }
            ;

            title = _data.Str("titlex");
            if (!string.IsNullOrEmpty(title))
            {
                c.AxisX.Title = new ChartTitle {
                    Text = title
                }
            }
            ;

            title = _data.Str("titley");
            if (!string.IsNullOrEmpty(title))
            {
                c.AxisY.Title = new ChartTitle {
                    Text = title
                }
            }
            ;

            if (ShowLegend)
            {
                c.Legend.Text = _data.Str("legtitle");
                if (Enum.TryParse <Dt.Charts.LegendPosition>(_data.Str("legpos"), out var pos))
                {
                    c.Legend.Alignment = GetLegendAlignment(pos);
                }
                if (Enum.TryParse <Orientation>(_data.Str("legorientation"), out var ori))
                {
                    c.Legend.Orientation = ori;
                }
            }
            else
            {
                c.Legend = null;
            }

            if (string.IsNullOrEmpty(FieldSeries))
            {
                LoadTable(c);
            }
            else
            {
                LoadMatrix(c);
            }
        }

        void LoadMatrix(SpreadChart p_chart)
        {
            // Build()中已判断空的情况
            RptData data = _part.Inst.Info.GetData(Tbl).Result;
            var     tbl  = data.Data.CreateMatrix(FieldX, FieldSeries, FieldY);

            for (int i = 0; i < tbl.Columns.Count; i++)
            {
                string colName = tbl.Columns[i].ID;
                if (colName == FieldX)
                {
                    continue;
                }

                SpreadDataSeries ser = new SpreadDataSeries();
                ser.Name = colName;
                DoubleSeriesCollection vals = new DoubleSeriesCollection();
                foreach (var row in tbl)
                {
                    try
                    {
                        double val = row.Double(i);
                        vals.Add(val);
                    }
                    catch
                    {
                        vals.Add(0);
                    }
                }
                ser.Values = vals;
                p_chart.DataSeries.Add(ser);
            }

            // 添加系列数据时已创建x轴Items,只能重新设置x轴
            p_chart.AxisX.Items.Clear();
            for (int i = 0; i < tbl.Count; i++)
            {
                p_chart.AxisX.Items.Add(tbl[i].Str(FieldX));
            }
        }

        void LoadTable(SpreadChart p_chart)
        {
            RptData                data = _part.Inst.Info.GetData(Tbl).Result;
            SpreadDataSeries       ser  = new SpreadDataSeries();
            DoubleSeriesCollection vals = new DoubleSeriesCollection();

            foreach (var row in data.Data)
            {
                try
                {
                    double val = row.Double(FieldY);
                    vals.Add(val);
                }
                catch
                {
                    vals.Add(0);
                }
            }
            ser.Values = vals;
            p_chart.DataSeries.Add(ser);

            p_chart.AxisX.Items.Clear();
            foreach (var row in data.Data)
            {
                p_chart.AxisX.Items.Add(row.Str(FieldX));
            }
        }

        /// <summary>
        /// 判断数据表字段是否完整
        /// </summary>
        /// <returns></returns>
        bool ValidFilds()
        {
            if (string.IsNullOrEmpty(Tbl))
            {
                Kit.Msg("数据源不可为空。");
                return(false);
            }

            string type = _data.Str("type");

            if (type == "Gantt")
            {
                if (string.IsNullOrEmpty(FieldZ) ||
                    string.IsNullOrEmpty(FieldX) ||
                    string.IsNullOrEmpty(FieldY))
                {
                    Kit.Msg("任务字段、起始时间字段及终止时间字段均不可为空,图表生成失败。");
                    return(false);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(FieldX) ||
                    string.IsNullOrEmpty(FieldY))
                {
                    Kit.Msg("分类字段和值字段不可为空,图表生成失败。");
                    return(false);
                }
            }
            return(true);
        }

        SpreadChartType GetChartType()
        {
            if (Enum.TryParse <ChartType>(_data.Str("type"), out var tp))
            {
                switch (tp)
                {
                case ChartType.Bar:
                    return(SpreadChartType.BarClustered);

                case ChartType.BarStacked:
                    return(SpreadChartType.BarStacked);

                case ChartType.Column:
                    return(SpreadChartType.ColumnClustered);

                case ChartType.ColumnStacked:
                    return(SpreadChartType.ColumnStacked);

                case ChartType.Line:
                    return(SpreadChartType.Line);

                case ChartType.LineSmoothed:
                    return(SpreadChartType.LineSmoothed);

                case ChartType.LineStacked:
                    return(SpreadChartType.LineStacked);

                case ChartType.LineSymbols:
                    return(SpreadChartType.LineWithMarkers);

                case ChartType.LineSymbolsSmoothed:
                    return(SpreadChartType.LineWithMarkersSmoothed);

                case ChartType.LineSymbolsStacked:
                    return(SpreadChartType.LineStackedWithMarkers);

                case ChartType.Pie:
                    return(SpreadChartType.Pie);

                case ChartType.PieExploded:
                    return(SpreadChartType.PieExploded);

                case ChartType.PieDoughnut:
                    return(SpreadChartType.PieDoughnut);

                case ChartType.PieExplodedDoughnut:
                    return(SpreadChartType.PieExplodedDoughnut);

                case ChartType.Area:
                    return(SpreadChartType.Area);

                case ChartType.AreaStacked:
                    return(SpreadChartType.AreaStacked);

                case ChartType.AreaStacked100pc:
                    return(SpreadChartType.AreaStacked);

                case ChartType.Radar:
                    return(SpreadChartType.Radar);

                case ChartType.RadarSymbols:
                    return(SpreadChartType.RadarWithMarkers);

                case ChartType.RadarFilled:
                    return(SpreadChartType.RadarFilled);

                case ChartType.XYPlot:
                    return(SpreadChartType.Scatter);

                case ChartType.Bubble:
                    return(SpreadChartType.Bubble);

                case ChartType.Candle:
                    return(SpreadChartType.StockHighLowOpenClose);
                }
            }
            return(SpreadChartType.ColumnClustered);
        }

        LegendAlignment GetLegendAlignment(Charts.LegendPosition pos)
        {
            switch (pos)
            {
            case Charts.LegendPosition.TopLeft:
                return(LegendAlignment.TopLeft);

            case Charts.LegendPosition.TopRight:
                return(LegendAlignment.TopRight);

            case Charts.LegendPosition.TopCenter:
                return(LegendAlignment.TopCenter);

            case Charts.LegendPosition.Left:
                return(LegendAlignment.MiddleLeft);

            case Charts.LegendPosition.Right:
                return(LegendAlignment.MiddleRight);

            case Charts.LegendPosition.BottomLeft:
                return(LegendAlignment.BottomLeft);

            case Charts.LegendPosition.BottomCenter:
                return(LegendAlignment.BottomCenter);

            case Charts.LegendPosition.BottomRight:
                return(LegendAlignment.BottomRight);
            }
            return(LegendAlignment.BottomCenter);
        }
예제 #15
0
파일: DataLabel.cs 프로젝트: Daoting/dt
 internal DataLabel(SpreadDataSeries dataSeries, int pointIndex) : base(dataSeries.Chart)
 {
     this.Init();
     this._dataSeries = dataSeries;
     this._pointIndex = pointIndex;
 }
예제 #16
0
파일: DataPoint.cs 프로젝트: Daoting/dt
 void Init()
 {
     this._pointIndex = -1;
     this._dataSeries = null;
 }
예제 #17
0
        private SpreadSurfaceChart CreateSurfaceChart(double xmin, double ymin, double xmax, double ymax, zfunc zfunc)
        {
            SpreadSurfaceChart chart = new SpreadSurfaceChart();
            int n = 21;
            var zdata = new double[n, n];
            var dx = (xmax - xmin) / (n - 1);
            var dy = (ymax - ymin) / (n - 1);

            for (int i = 0; i < n; i++)
            {
                SpreadDataSeries ds = new SpreadDataSeries();
                ds.Values = new DoubleSeriesCollection();
                for (int j = 0; j < n; j++)
                {
                    double value = zfunc(xmin + i * dx, ymin + j * dy);
                    ds.Values.Add(value);
                }
                chart.DataSeries.Add(ds);
            }
            return chart;
        }