internal SLDataSeries Clone() { SLDataSeries ds = new SLDataSeries(this.Options.ShapeProperties.listThemeColors, this.Options.ShapeProperties.ThrowExceptionsIfAny); ds.ChartType = this.ChartType; ds.Index = this.Index; ds.Order = this.Order; ds.IsStringReference = this.IsStringReference; ds.StringReference = this.StringReference.Clone(); ds.NumericValue = this.NumericValue; ds.Options = this.Options.Clone(); List <int> keys = this.DataPointOptionsList.Keys.ToList <int>(); ds.DataPointOptionsList = new Dictionary <int, SLDataPointOptions>(); foreach (int index in keys) { ds.DataPointOptionsList[index] = this.DataPointOptionsList[index].Clone(); } if (this.GroupDataLabelOptions != null) { ds.GroupDataLabelOptions = this.GroupDataLabelOptions.Clone(); } keys = this.DataLabelOptionsList.Keys.ToList <int>(); ds.DataLabelOptionsList = new Dictionary <int, SLDataLabelOptions>(); foreach (int index in keys) { ds.DataLabelOptionsList[index] = this.DataLabelOptionsList[index].Clone(); } ds.BubbleSize = this.BubbleSize.Clone(); ds.AxisData = this.AxisData.Clone(); ds.NumberData = this.NumberData.Clone(); return(ds); }
internal SLDataSeries Clone() { SLDataSeries ds = new SLDataSeries(this.Options.ShapeProperties.listThemeColors); ds.ChartType = this.ChartType; ds.Index = this.Index; ds.Order = this.Order; ds.IsStringReference = this.IsStringReference; ds.StringReference = this.StringReference.Clone(); ds.NumericValue = this.NumericValue; ds.Options = this.Options.Clone(); List<int> keys = this.DataPointOptionsList.Keys.ToList<int>(); ds.DataPointOptionsList = new Dictionary<int, SLDataPointOptions>(); foreach (int index in keys) { ds.DataPointOptionsList[index] = this.DataPointOptionsList[index].Clone(); } if (this.GroupDataLabelOptions != null) ds.GroupDataLabelOptions = this.GroupDataLabelOptions.Clone(); keys = this.DataLabelOptionsList.Keys.ToList<int>(); ds.DataLabelOptionsList = new Dictionary<int, SLDataLabelOptions>(); foreach (int index in keys) { ds.DataLabelOptionsList[index] = this.DataLabelOptionsList[index].Clone(); } ds.BubbleSize = this.BubbleSize.Clone(); ds.AxisData = this.AxisData.Clone(); ds.NumberData = this.NumberData.Clone(); return ds; }
/// <summary> /// Set a bubble chart using one of the built-in bubble chart types. /// </summary> /// <param name="ChartType">A built-in bubble chart type.</param> /// <param name="Options">Chart customization options.</param> public void SetChartType(SLBubbleChartType ChartType, SLBubbleChartOptions Options) { this.Is3D = SLChartTool.Is3DChart(ChartType); int i, index; SLNumberLiteral nl = new SLNumberLiteral(); nl.FormatCode = "General"; nl.PointCount = (uint)(this.EndRowIndex - this.StartRowIndex); for (i = 0; i < (this.EndRowIndex - this.StartRowIndex); ++i) { nl.Points.Add(new SLNumericPoint() { Index = (uint)i, NumericValue = "1" }); } double fTemp = 0; List<SLDataSeries> series = new List<SLDataSeries>(); SLDataSeries ser; for (index = 0, i = 0; i < this.PlotArea.DataSeries.Count; ++index, ++i) { ser = new SLDataSeries(this.listThemeColors); ser.Index = (uint)index; ser.Order = (uint)index; ser.IsStringReference = null; ser.StringReference = this.PlotArea.DataSeries[i].StringReference.Clone(); ser.AxisData = this.PlotArea.DataSeries[i].AxisData.Clone(); if (this.PlotArea.DataSeries[i].StringReference.Points.Count > 0) { foreach (var pt in ser.AxisData.StringReference.Points) { ++pt.Index; } // move one row up --ser.AxisData.StringReference.StartRowIndex; ser.AxisData.StringReference.RefreshFormula(); ser.AxisData.StringReference.Points.Insert(0, this.PlotArea.DataSeries[i].StringReference.Points[0].Clone()); ++ser.AxisData.StringReference.PointCount; } ser.NumberData = this.PlotArea.DataSeries[i].NumberData.Clone(); if (this.PlotArea.DataSeries[i].StringReference.Points.Count > 1) { foreach (var pt in ser.NumberData.NumberReference.NumberingCache.Points) { ++pt.Index; } --ser.NumberData.NumberReference.StartRowIndex; ser.NumberData.NumberReference.RefreshFormula(); if (double.TryParse(this.PlotArea.DataSeries[i].StringReference.Points[1].NumericValue, NumberStyles.Any, CultureInfo.InvariantCulture, out fTemp)) { ser.NumberData.NumberReference.NumberingCache.Points.Insert(0, new SLNumericPoint() { Index = 0, NumericValue = fTemp.ToString(CultureInfo.InvariantCulture) }); } else { ser.NumberData.NumberReference.NumberingCache.Points.Insert(0, new SLNumericPoint() { Index = 0, NumericValue = "0" }); } ++ser.NumberData.NumberReference.NumberingCache.PointCount; } ++i; if (i < this.PlotArea.DataSeries.Count) { ser.BubbleSize = this.PlotArea.DataSeries[i].NumberData.Clone(); if (this.PlotArea.DataSeries[i].StringReference.Points.Count > 2) { foreach (var pt in ser.BubbleSize.NumberReference.NumberingCache.Points) { ++pt.Index; } --ser.BubbleSize.NumberReference.StartRowIndex; ser.BubbleSize.NumberReference.RefreshFormula(); if (double.TryParse(this.PlotArea.DataSeries[i].StringReference.Points[2].NumericValue, NumberStyles.Any, CultureInfo.InvariantCulture, out fTemp)) { ser.BubbleSize.NumberReference.NumberingCache.Points.Insert(0, new SLNumericPoint() { Index = 0, NumericValue = fTemp.ToString(CultureInfo.InvariantCulture) }); } else { ser.BubbleSize.NumberReference.NumberingCache.Points.Insert(0, new SLNumericPoint() { Index = 0, NumericValue = "0" }); } ++ser.BubbleSize.NumberReference.NumberingCache.PointCount; } } else { ser.BubbleSize.UseNumberLiteral = true; ser.BubbleSize.NumberLiteral = nl.Clone(); } series.Add(ser); } this.PlotArea.DataSeries = series; SLDataSeriesChartType vType; int iChartType; switch (ChartType) { case SLBubbleChartType.Bubble: vType = SLDataSeriesChartType.BubbleChart; this.IsCombinable = SLChartTool.IsCombinationChartFriendly(vType); iChartType = (int)vType; this.PlotArea.UsedChartTypes[iChartType] = true; this.PlotArea.UsedChartOptions[iChartType].BubbleScale = 100; if (Options != null) this.PlotArea.UsedChartOptions[iChartType].MergeOptions(Options); this.PlotArea.SetDataSeriesChartType(vType); foreach (SLDataSeries ds in this.PlotArea.DataSeries) { ds.Options.Bubble3D = false; } this.SetPlotAreaValueAxes(); this.PlotArea.HasPrimaryAxes = true; break; case SLBubbleChartType.Bubble3D: vType = SLDataSeriesChartType.BubbleChart; this.IsCombinable = SLChartTool.IsCombinationChartFriendly(vType); iChartType = (int)vType; this.PlotArea.UsedChartTypes[iChartType] = true; this.PlotArea.UsedChartOptions[iChartType].BubbleScale = 100; if (Options != null) this.PlotArea.UsedChartOptions[iChartType].MergeOptions(Options); this.PlotArea.SetDataSeriesChartType(vType); foreach (SLDataSeries ds in this.PlotArea.DataSeries) { ds.Options.Bubble3D = true; } this.SetPlotAreaValueAxes(); this.PlotArea.HasPrimaryAxes = true; break; } }
private List<SLC.SLDataSeries> FillChartDataSeries(string WorksheetName, int StartRowIndex, int StartColumnIndex, int EndRowIndex, int EndColumnIndex, bool RowsAsDataSeries, bool ShowHiddenData) { List<SLC.SLDataSeries> series = new List<SLC.SLDataSeries>(); int i, j; SLCell c; SLCellPoint pt; Dictionary<int, bool> HiddenRows = new Dictionary<int, bool>(); Dictionary<int, bool> HiddenColumns = new Dictionary<int, bool>(); Dictionary<SLCellPoint, SLCell> cellstore = new Dictionary<SLCellPoint, SLCell>(); #region GetCells for (i = StartRowIndex; i <= EndRowIndex; ++i) { HiddenRows[i] = false; } for (j = StartColumnIndex; j <= EndColumnIndex; ++j) { HiddenColumns[j] = false; } bool bFound = false; string sWorksheetRelID = string.Empty; if (WorksheetName.Equals(gsSelectedWorksheetName, StringComparison.OrdinalIgnoreCase)) { bFound = false; } else { bFound = false; foreach (SLSheet sheet in slwb.Sheets) { if (sheet.Name.Equals(WorksheetName, StringComparison.OrdinalIgnoreCase)) { bFound = true; sWorksheetRelID = sheet.Id; break; } } } if (bFound) { Dictionary<string, SLCellPoint> cellref = new Dictionary<string, SLCellPoint>(); for (i = StartRowIndex; i <= EndRowIndex; ++i) { for (j = StartColumnIndex; j <= EndColumnIndex; ++j) { pt = new SLCellPoint(i, j); cellref[SLTool.ToCellReference(i, j)] = pt; } } WorksheetPart wsp = (WorksheetPart)wbp.GetPartById(sWorksheetRelID); Row row; Column column; Cell cell; if (!ShowHiddenData) { // running it twice because Row contains Cell classes and it's easier this way using (OpenXmlReader oxr = OpenXmlReader.Create(wsp)) { while (oxr.Read()) { if (oxr.ElementType == typeof(Row)) { row = (Row)oxr.LoadCurrentElement(); if (row.RowIndex != null) { foreach (var rowindex in HiddenRows.Keys) { if (row.RowIndex.Value == rowindex && row.Hidden != null && row.Hidden.Value) { HiddenRows[rowindex] = true; } } } } } } } using (OpenXmlReader oxr = OpenXmlReader.Create(wsp)) { while (oxr.Read()) { if (oxr.ElementType == typeof(Column)) { if (!ShowHiddenData) { column = (Column)oxr.LoadCurrentElement(); foreach (var colindex in HiddenColumns.Keys) { if (column.Min <= colindex && colindex <= column.Max && column.Hidden != null && column.Hidden.Value) { HiddenColumns[colindex] = true; } } } } else if (oxr.ElementType == typeof(Cell)) { cell = (Cell)oxr.LoadCurrentElement(); if (cell.CellReference != null) { if (cellref.ContainsKey(cell.CellReference.Value)) { c = new SLCell(); c.FromCell(cell); cellstore[cellref[cell.CellReference.Value]] = c.Clone(); } } } } } } else { SLRowProperties rp; SLColumnProperties cp; if (!ShowHiddenData) { for (j = StartColumnIndex; j <= EndColumnIndex; ++j) { if (slws.ColumnProperties.ContainsKey(j)) { cp = slws.ColumnProperties[j]; if (cp.Hidden) HiddenColumns[j] = true; } } } for (i = StartRowIndex; i <= EndRowIndex; ++i) { if (!ShowHiddenData && slws.RowProperties.ContainsKey(i)) { rp = slws.RowProperties[i]; if (rp.Hidden) HiddenRows[i] = true; } for (j = StartColumnIndex; j <= EndColumnIndex; ++j) { pt = new SLCellPoint(i, j); if (slws.Cells.ContainsKey(pt)) { cellstore[pt] = slws.Cells[pt].Clone(); } } } } #endregion int index = 0; int index2 = 0; string sCellValue; string sFormatCode; SLC.SLDataSeries ser; SLC.SLStringReference sr; SLC.SLNumberReference nr; SLStyle style; bool bIsStringReference = true; // we're going to assume that the format code applies to all in the "category" cells. string sAxisFormatCode = string.Empty; SLC.SLAxisDataSourceType cat = new SLC.SLAxisDataSourceType(); if (RowsAsDataSeries) { bIsStringReference = true; sAxisFormatCode = SLConstants.NumberFormatGeneral; pt = new SLCellPoint(StartRowIndex, StartColumnIndex + 1); if (cellstore.ContainsKey(pt)) { // dates are also numbers, so we lump it together if (cellstore[pt].DataType == CellValues.Number) { bIsStringReference = false; style = new SLStyle(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, new List<System.Drawing.Color>(), new List<System.Drawing.Color>()); style.FromHash(listStyle[(int)cellstore[pt].StyleIndex]); this.TranslateStylesToStyleIds(ref style); sAxisFormatCode = style.FormatCode; } } sr = new SLC.SLStringReference(); nr = new SLC.SLNumberReference(); if (bIsStringReference) { cat.UseStringReference = true; sr = new SLC.SLStringReference(); sr.WorksheetName = WorksheetName; sr.StartRowIndex = StartRowIndex; sr.StartColumnIndex = StartColumnIndex + 1; sr.EndRowIndex = StartRowIndex; sr.EndColumnIndex = EndColumnIndex; sr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, StartRowIndex, StartColumnIndex + 1, StartRowIndex, EndColumnIndex); } else { cat.UseNumberReference = true; nr.WorksheetName = WorksheetName; nr.StartRowIndex = StartRowIndex; nr.StartColumnIndex = StartColumnIndex + 1; nr.EndRowIndex = StartRowIndex; nr.EndColumnIndex = EndColumnIndex; nr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, StartRowIndex, StartColumnIndex + 1, StartRowIndex, EndColumnIndex); nr.NumberingCache.FormatCode = sAxisFormatCode; } index2 = 0; // if the header row is hidden, I don't know what to do... for (j = StartColumnIndex + 1; j <= EndColumnIndex; ++j) { if (HiddenColumns.ContainsKey(j) && !HiddenColumns[j]) { pt = new SLCellPoint(StartRowIndex, j); sCellValue = string.Empty; if (cellstore.ContainsKey(pt)) { c = cellstore[pt]; sCellValue = this.GetCellTrueValue(c); if (bIsStringReference) { sr.Points.Add(new SLC.SLStringPoint() { Index = (uint)index2, NumericValue = sCellValue }); } else { nr.NumberingCache.Points.Add(new SLC.SLNumericPoint() { Index = (uint)index2, NumericValue = sCellValue }); } } ++index2; } } if (bIsStringReference) { sr.PointCount = (uint)index2; cat.StringReference = sr; } else { nr.NumberingCache.PointCount = (uint)index2; cat.NumberReference = nr; } index = 0; for (i = StartRowIndex + 1; i <= EndRowIndex; ++i) { if (HiddenRows.ContainsKey(i) && !HiddenRows[i]) { ser = new SLC.SLDataSeries(SimpleTheme.listThemeColors); ser.Index = (uint)index; ser.Order = (uint)index; ser.IsStringReference = true; sr = new SLC.SLStringReference(); pt = new SLCellPoint(i, StartColumnIndex); sCellValue = string.Empty; if (cellstore.ContainsKey(pt)) { c = cellstore[pt]; sCellValue = this.GetCellTrueValue(c); } sr.WorksheetName = WorksheetName; sr.StartRowIndex = i; sr.StartColumnIndex = StartColumnIndex; sr.EndRowIndex = i; sr.EndColumnIndex = StartColumnIndex; sr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, i, StartColumnIndex); sr.PointCount = 1; sr.Points.Add(new SLC.SLStringPoint() { Index = 0, NumericValue = sCellValue }); ser.StringReference = sr; ser.AxisData = cat.Clone(); ser.NumberData.UseNumberReference = true; nr = new SLC.SLNumberReference(); nr.WorksheetName = WorksheetName; nr.StartRowIndex = i; nr.StartColumnIndex = StartColumnIndex + 1; nr.EndRowIndex = i; nr.EndColumnIndex = EndColumnIndex; nr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, i, StartColumnIndex + 1, i, EndColumnIndex); nr.NumberingCache.FormatCode = SLConstants.NumberFormatGeneral; index2 = 0; for (j = StartColumnIndex + 1; j <= EndColumnIndex; ++j) { if (HiddenColumns.ContainsKey(j) && !HiddenColumns[j]) { pt = new SLCellPoint(i, j); sCellValue = string.Empty; sFormatCode = string.Empty; if (cellstore.ContainsKey(pt)) { c = cellstore[pt]; sCellValue = this.GetCellTrueValue(c); style = new SLStyle(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, new List<System.Drawing.Color>(), new List<System.Drawing.Color>()); style.FromHash(listStyle[(int)c.StyleIndex]); this.TranslateStylesToStyleIds(ref style); if (style.HasNumberingFormat) sFormatCode = style.FormatCode; nr.NumberingCache.Points.Add(new SLC.SLNumericPoint() { FormatCode = sFormatCode, Index = (uint)index2, NumericValue = sCellValue }); } ++index2; } } nr.NumberingCache.PointCount = (uint)index2; ser.NumberData.NumberReference = nr; series.Add(ser); ++index; } } // end of rows as data series } else { bIsStringReference = true; sAxisFormatCode = SLConstants.NumberFormatGeneral; pt = new SLCellPoint(StartRowIndex + 1, StartColumnIndex); if (cellstore.ContainsKey(pt)) { // dates are also numbers, so we lump it together if (cellstore[pt].DataType == CellValues.Number) { bIsStringReference = false; style = new SLStyle(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, new List<System.Drawing.Color>(), new List<System.Drawing.Color>()); style.FromHash(listStyle[(int)cellstore[pt].StyleIndex]); this.TranslateStylesToStyleIds(ref style); sAxisFormatCode = style.FormatCode; } } sr = new SLC.SLStringReference(); nr = new SLC.SLNumberReference(); if (bIsStringReference) { cat.UseStringReference = true; sr.WorksheetName = WorksheetName; sr.StartRowIndex = StartRowIndex + 1; sr.StartColumnIndex = StartColumnIndex; sr.EndRowIndex = EndRowIndex; sr.EndColumnIndex = StartColumnIndex; sr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, StartRowIndex + 1, StartColumnIndex, EndRowIndex, StartColumnIndex); } else { cat.UseNumberReference = true; nr.WorksheetName = WorksheetName; nr.StartRowIndex = StartRowIndex + 1; nr.StartColumnIndex = StartColumnIndex; nr.EndRowIndex = EndRowIndex; nr.EndColumnIndex = StartColumnIndex; nr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, StartRowIndex + 1, StartColumnIndex, EndRowIndex, StartColumnIndex); nr.NumberingCache.FormatCode = sAxisFormatCode; } index2 = 0; // if the header column is hidden, I don't know what to do... for (i = StartRowIndex + 1; i <= EndRowIndex; ++i) { if (HiddenRows.ContainsKey(i) && !HiddenRows[i]) { pt = new SLCellPoint(i, StartColumnIndex); sCellValue = string.Empty; if (cellstore.ContainsKey(pt)) { c = cellstore[pt]; sCellValue = this.GetCellTrueValue(c); if (bIsStringReference) { sr.Points.Add(new SLC.SLStringPoint() { Index = (uint)index2, NumericValue = sCellValue }); } else { nr.NumberingCache.Points.Add(new SLC.SLNumericPoint() { Index = (uint)index2, NumericValue = sCellValue }); } } ++index2; } } if (bIsStringReference) { sr.PointCount = (uint)index2; cat.StringReference = sr; } else { nr.NumberingCache.PointCount = (uint)index2; cat.NumberReference = nr; } index = 0; for (j = StartColumnIndex + 1; j <= EndColumnIndex; ++j) { if (HiddenColumns.ContainsKey(j) && !HiddenColumns[j]) { ser = new SLC.SLDataSeries(SimpleTheme.listThemeColors); ser.Index = (uint)index; ser.Order = (uint)index; ser.IsStringReference = true; sr = new SLC.SLStringReference(); pt = new SLCellPoint(StartRowIndex, j); sCellValue = string.Empty; if (cellstore.ContainsKey(pt)) { c = cellstore[pt]; sCellValue = this.GetCellTrueValue(c); } sr.WorksheetName = WorksheetName; sr.StartRowIndex = StartRowIndex; sr.StartColumnIndex = j; sr.EndRowIndex = StartRowIndex; sr.EndColumnIndex = j; sr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, StartRowIndex, j); sr.PointCount = 1; sr.Points.Add(new SLC.SLStringPoint() { Index = 0, NumericValue = sCellValue }); ser.StringReference = sr; ser.AxisData = cat.Clone(); ser.NumberData.UseNumberReference = true; nr = new SLC.SLNumberReference(); nr.WorksheetName = WorksheetName; nr.StartRowIndex = StartRowIndex + 1; nr.StartColumnIndex = j; nr.EndRowIndex = EndRowIndex; nr.EndColumnIndex = j; nr.Formula = SLC.SLChartTool.GetChartReferenceFormula(WorksheetName, StartRowIndex + 1, j, EndRowIndex, j); nr.NumberingCache.FormatCode = SLConstants.NumberFormatGeneral; index2 = 0; for (i = StartRowIndex + 1; i <= EndRowIndex; ++i) { if (HiddenRows.ContainsKey(i) && !HiddenRows[i]) { pt = new SLCellPoint(i, j); sCellValue = string.Empty; sFormatCode = string.Empty; if (cellstore.ContainsKey(pt)) { c = cellstore[pt]; sCellValue = this.GetCellTrueValue(c); style = new SLStyle(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, new List<System.Drawing.Color>(), new List<System.Drawing.Color>()); style.FromHash(listStyle[(int)c.StyleIndex]); this.TranslateStylesToStyleIds(ref style); if (style.HasNumberingFormat) sFormatCode = style.FormatCode; nr.NumberingCache.Points.Add(new SLC.SLNumericPoint() { FormatCode = sFormatCode, Index = (uint)index2, NumericValue = sCellValue }); } ++index2; } } nr.NumberingCache.PointCount = (uint)index2; ser.NumberData.NumberReference = nr; series.Add(ser); ++index; } } // end of columns as data series } return series; }