Пример #1
0
        void AddNewChart(object sender, RoutedEventArgs e)
        {
            if (_excel.ActiveSheet.Selections.Count == 0)
            {
                Kit.Msg("请选择单元格区域!");
                return;
            }

            CellRange range = _excel.ActiveSheet.Selections[0];

            if (range.Row < 0 || range.Column < 0)
            {
                Kit.Msg("单元格区域无效!");
                return;
            }

            string rangeFormula = _excel.ActiveSheet.Cells[range.Row, range.Column, range.RowCount + range.Row - 1, range.ColumnCount + range.Column - 1].ToString(_excel.ActiveSheet.Cells[0, 0]);

            rangeFormula = "'" + _excel.ActiveSheet.Name + "'!" + rangeFormula;

            SpreadChartType chartType = (SpreadChartType)Enum.Parse(typeof(SpreadChartType), (string)_cbTypes.SelectedItem, false);
            //SpreadChart chart = _excel.ActiveSheet.AddChart("CustomChart" + customChartIndex.ToString(), chartType, rangeFormula, 10, 10, 400, 290);
            SpreadChart chart = _excel.ActiveSheet.AddChart("CustomChart" + customChartIndex.ToString(), chartType, rangeFormula, 10, 0, 10, 0, 400, 290);

            _excel.ActiveSheet.ChartSelectionChanged += ChartSelectionChanged;

            chart.ChartTitle      = new ChartTitle();
            chart.ChartTitle.Text = chartType.ToString();
            chart.IsSelected      = true;

            customChartIndex++;
        }
Пример #2
0
 public static bool IsChartWithMarker(SpreadChartType chartType)
 {
     if (!chartType.ToString().ToLower().Contains("marker"))
     {
         return(chartType == SpreadChartType.Scatter);
     }
     return(true);
 }
Пример #3
0
 public static bool IsLineOrLineWithMarkerChart(SpreadChartType chartType)
 {
     if (((((chartType != SpreadChartType.Line) && (chartType != SpreadChartType.LineSmoothed)) && ((chartType != SpreadChartType.LineStacked) && (chartType != SpreadChartType.LineStacked100pc))) && (((chartType != SpreadChartType.LineWithMarkers) && (chartType != SpreadChartType.LineWithMarkersSmoothed)) && ((chartType != SpreadChartType.LineStackedWithMarkers) && (chartType != SpreadChartType.LineStacked100pcWithMarkers)))) && ((((chartType != SpreadChartType.Scatter) && (chartType != SpreadChartType.ScatterLines)) && ((chartType != SpreadChartType.ScatterLinesWithMarkers) && (chartType != SpreadChartType.ScatterLinesSmoothed))) && ((chartType != SpreadChartType.ScatterLinesSmoothedWithMarkers) && (chartType != SpreadChartType.Radar))))
     {
         return(chartType == SpreadChartType.RadarWithMarkers);
     }
     return(true);
 }
Пример #4
0
 public static bool IsSymbolChart(SpreadChartType chartType)
 {
     if (((((chartType != SpreadChartType.BarClustered) && (chartType != SpreadChartType.BarStacked)) && ((chartType != SpreadChartType.BarStacked100pc) && (chartType != SpreadChartType.ColumnClustered))) && (((chartType != SpreadChartType.ColumnStacked) && (chartType != SpreadChartType.ColumnStacked100pc)) && ((chartType != SpreadChartType.Bubble) && (chartType != SpreadChartType.Pie)))) && ((chartType != SpreadChartType.PieExploded) && (chartType != SpreadChartType.PieDoughnut)))
     {
         return(chartType == SpreadChartType.PieExplodedDoughnut);
     }
     return(true);
 }
Пример #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
 void _cbTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (_selectedChart != null)
     {
         SpreadChartType chartType       = (SpreadChartType)Enum.Parse(typeof(SpreadChartType), (string)_cbTypes.SelectedItem, false);
         var             changeChartType = new ChangeChartTypeAction(_selectedChart, chartType);
         _excel.UndoManager.Do(changeChartType);
         _selectedChart.ChartTitle.Text = _selectedChart.ChartType.ToString();
         _excel.RefreshCharts(_selectedChart);
     }
 }
Пример #7
0
        public static SpreadDataSeries CreateDataSeries(SpreadChartType chartType)
        {
            switch (SpreadChartUtility.GetDataDimension(chartType))
            {
            case 1:
                return(new SpreadDataSeries());

            case 2:
                return(new SpreadXYDataSeries());

            case 3:
                return(new SpreadBubbleSeries());

            case 5:
                return(new SpreadOpenHighLowCloseSeries());
            }
            return(new SpreadDataSeries());
        }
Пример #8
0
        public static int GetDataDimension(SpreadChartType chartType)
        {
            switch (chartType)
            {
            case SpreadChartType.BarClustered:
            case SpreadChartType.BarStacked:
            case SpreadChartType.BarStacked100pc:
            case SpreadChartType.ColumnClustered:
            case SpreadChartType.ColumnStacked:
            case SpreadChartType.ColumnStacked100pc:
            case SpreadChartType.Line:
            case SpreadChartType.LineStacked:
            case SpreadChartType.LineStacked100pc:
            case SpreadChartType.LineWithMarkers:
            case SpreadChartType.LineStackedWithMarkers:
            case SpreadChartType.LineStacked100pcWithMarkers:
            case SpreadChartType.Pie:
            case SpreadChartType.PieExploded:
            case SpreadChartType.PieDoughnut:
            case SpreadChartType.PieExplodedDoughnut:
            case SpreadChartType.Area:
            case SpreadChartType.AreaStacked:
            case SpreadChartType.AreaStacked100pc:
            case SpreadChartType.Radar:
            case SpreadChartType.RadarWithMarkers:
            case SpreadChartType.RadarFilled:
                return(1);

            case SpreadChartType.Scatter:
            case SpreadChartType.ScatterLines:
            case SpreadChartType.ScatterLinesWithMarkers:
            case SpreadChartType.ScatterLinesSmoothed:
            case SpreadChartType.ScatterLinesSmoothedWithMarkers:
                return(2);

            case SpreadChartType.Bubble:
                return(3);

            case SpreadChartType.StockHighLowOpenClose:
                return(5);
            }
            return(1);
        }
Пример #9
0
 public static bool Is100PercentChart(SpreadChartType charType)
 {
     return(charType.ToString().ToLower().Contains("100pc"));
 }
Пример #10
0
 public static bool IsStackedChart(SpreadChartType charType)
 {
     return(charType.ToString().ToLower().Contains("stacked"));
 }
Пример #11
0
 public static bool IsSeriesHasMarker(SpreadChartType charType)
 {
     return(charType.ToString().ToLower().Contains("marker"));
 }
Пример #12
0
 public static bool IsRadarChart(SpreadChartType charType)
 {
     return(charType.ToString().ToLower().Contains("radar"));
 }
Пример #13
0
 public static bool IsPieChart(SpreadChartType charType)
 {
     return(charType.ToString().ToLower().Contains("pie"));
 }
Пример #14
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);
        }
Пример #15
0
 public static bool IsColumnChart(SpreadChartType chartType)
 {
     return(chartType.ToString().ToLower().Contains("column"));
 }
Пример #16
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);
        }
Пример #17
0
 public static bool IsBubbleChart(SpreadChartType chartType)
 {
     return(chartType.ToString().ToLower().Contains("bubble"));
 }
Пример #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Dt.Cells.UndoRedo.ChangeChartTypeAction" /> class.
 /// </summary>
 /// <param name="chart">The chart.</param>
 /// <param name="newType">The new type.</param>
 public ChangeChartTypeAction(SpreadChart chart, SpreadChartType newType)
 {
     _chart   = chart;
     _oldType = chart.ChartType;
     _newType = newType;
 }
Пример #19
0
        bool ChangeChartType(SpreadChartType fromChartType, SpreadChartType toChartType)
        {
            _chart.SuspendEvents();
            bool flag = false;

            try
            {
                int  dataDimension = Dt.Cells.Data.SpreadChartUtility.GetDataDimension(fromChartType);
                int  num2          = Dt.Cells.Data.SpreadChartUtility.GetDataDimension(toChartType);
                bool flag2         = fromChartType.ToString().ToLower().Contains("bar");
                bool flag3         = toChartType.ToString().ToLower().Contains("bar");
                if (dataDimension != num2)
                {
                    if (toChartType == SpreadChartType.StockHighLowOpenClose)
                    {
                        flag = ChangeToStockChart(fromChartType, toChartType);
                    }
                    else if (fromChartType == SpreadChartType.StockHighLowOpenClose)
                    {
                        flag = ChangeFromStockChart(fromChartType, toChartType);
                    }
                    else if (num2 != 1)
                    {
                        flag = ChangeChartTypeToMulti(fromChartType, toChartType);
                    }
                    else if (num2 == 1)
                    {
                        flag = ChangeChartTypeOne(fromChartType, toChartType);
                    }
                }
                else
                {
                    if (flag2 != flag3)
                    {
                        AxisType axisType = _chart.AxisY.AxisType;
                        _chart.AxisY.AxisType = _chart.AxisX.AxisType;
                        _chart.AxisX.AxisType = axisType;
                        string itemsFormula = _chart.AxisY.ItemsFormula;
                        _chart.AxisY.ItemsFormula = _chart.AxisX.ItemsFormula;
                        _chart.AxisX.ItemsFormula = itemsFormula;
                    }
                    _chart.ChartType = toChartType;
                }
                if (flag2 != flag3)
                {
                    if (flag3)
                    {
                        if (_chart.AxisX != null)
                        {
                            _chart.AxisX.ShowMajorGridlines = true;
                        }
                        if (_chart.AxisY != null)
                        {
                            _chart.AxisY.ShowMajorGridlines = false;
                        }
                    }
                    if (flag2)
                    {
                        if (_chart.AxisY != null)
                        {
                            _chart.AxisY.ShowMajorGridlines = true;
                        }
                        if (_chart.AxisX != null)
                        {
                            _chart.AxisX.ShowMajorGridlines = false;
                        }
                    }
                }
                if (!Dt.Cells.Data.SpreadChartUtility.IsChartWithMarker(toChartType))
                {
                    return(flag);
                }
                foreach (SpreadDataSeries series in _chart.DataSeries)
                {
                    if (series.MarkerType == MarkerType.None)
                    {
                        series.MarkerType = MarkerType.Automatic;
                    }
                    if ((series.MarkerType != MarkerType.None) && ((series.MarkerSize.IsEmpty || (series.MarkerSize.Width == 0.0)) || (series.MarkerSize.Height == 0.0)))
                    {
                        series.MarkerSize = new Size(7.0, 7.0);
                    }
                }
            }
            finally
            {
                _chart.ResumeEvents();
            }
            return(flag);
        }