private void SetWaterfallStructure(BarChartSeries seriesItem, Column dataColumn) { var dataPoints = seriesItem.Elements <DataPoint>(); var labels = seriesItem.FirstElement <DataLabels>(); bool isFirstBar = dataColumn.Data[0] != null; if (!isFirstBar) { int valueToHideInd = dataColumn.Data.IndexOf(dataColumn.Data.First(v => v != null)); DataPoint dataPoint = dataPoints.FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == valueToHideInd); dataPoint.RemoveAllChildren <ChartShapeProperties>(); ChartShapeProperties chartShapeProperties = new ChartShapeProperties(); chartShapeProperties.Append(new A.NoFill()); dataPoint.Append(chartShapeProperties); DataLabel label = labels.Elements <DataLabel>().FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == valueToHideInd); if (label != null) { label.FirstElement <ShowValue>().Val.Value = false; } } labels.FirstElement <ShowValue>().Val.Value = false; }
void setChartData(ChartPart chartPart1, ChartDataHolder[] ChartDataSlide) { ChartSpace chartSpace = chartPart1.ChartSpace; DocumentFormat.OpenXml.Drawing.Charts.Chart chart1 = chartSpace.GetFirstChild <DocumentFormat.OpenXml.Drawing.Charts.Chart>(); PlotArea plotArea1 = chart1.GetFirstChild <PlotArea>(); BarChart barChart1 = plotArea1.GetFirstChild <BarChart>(); //BarChartSeries barChartSeries1 = barChart1.Elements<BarChartSeries>().ElementAtOrDefault(2); for (int i = 0; i < barChart1.Elements <BarChartSeries>().Count(); i++) { BarChartSeries barChartSeries = barChart1.Elements <BarChartSeries>().ElementAtOrDefault(i); ChartDataSlide dataModel = ChartDataSlide.ElementAtOrDefault(i).chartData; SeriesText seriesText = barChartSeries.Elements <SeriesText>().ElementAtOrDefault(0); if (seriesText != null) { var stringReference = seriesText.Descendants <StringReference>().FirstOrDefault(); var stringCache = stringReference.Descendants <StringCache>().FirstOrDefault(); var stringPoint = stringCache.Descendants <StringPoint>().FirstOrDefault(); var barLabel = stringPoint.GetFirstChild <NumericValue>(); barLabel.Text = ChartDataSlide.ElementAtOrDefault(i).seriesText; } if (barChartSeries != null) { Values values1 = barChartSeries.GetFirstChild <Values>(); NumberReference numberReference1 = values1.GetFirstChild <NumberReference>(); NumberingCache numberingCache1 = numberReference1.GetFirstChild <NumberingCache>(); NumericPoint numericPoint1 = numberingCache1.GetFirstChild <NumericPoint>(); NumericPoint numericPoint2 = numberingCache1.Elements <NumericPoint>().ElementAt(1); NumericPoint numericPoint3 = numberingCache1.Elements <NumericPoint>().ElementAt(2); NumericValue numericValue1 = numericPoint1.GetFirstChild <NumericValue>(); //numericValue1.Text = ".50"; if (numericValue1 != null) { numericValue1.Text = dataModel.Interaction.ToString(); } NumericValue numericValue2 = numericPoint2.GetFirstChild <NumericValue>(); //numericValue2.Text = ".10"; if (numericValue2 != null) { numericValue2.Text = dataModel.Knowlegde.ToString(); } NumericValue numericValue3 = numericPoint3.GetFirstChild <NumericValue>(); //numericValue3.Text = ".40"; if (numericValue3 != null) { numericValue3.Text = dataModel.Image.ToString(); } } } chartSpace.Save(); }
private void FillPoints(string baseFormula, String mode, List <String> data) { int idx = data.Count; ChartPart cp = Document.MainDocumentPart.ChartParts.FirstOrDefault(); Chart chart = cp.ChartSpace.Elements <Chart>().FirstOrDefault(); BarChart barchart = chart.PlotArea.Elements <BarChart>().FirstOrDefault(); BarChartSeries series = barchart.Elements <BarChartSeries>().FirstOrDefault(); CategoryAxisData labels = new CategoryAxisData(); DocumentFormat.OpenXml.Drawing.Charts.Values values = new DocumentFormat.OpenXml.Drawing.Charts.Values(); NumberReference nref = new NumberReference(); string formula = baseFormula + (idx + 1); DocumentFormat.OpenXml.Drawing.Charts.Formula f = new DocumentFormat.OpenXml.Drawing.Charts.Formula(); f.Text = formula; Log.Info(formula); nref.Formula = f; NumberingCache nc = new NumberingCache();//nref.Descendants<NumberingCache>().First(); nc.PointCount = new PointCount(); nc.PointCount.Val = (uint)idx; int pointIndex = 0; foreach (string val in data) { NumericPoint point = new NumericPoint(); point.Index = (uint)pointIndex; NumericValue value = new NumericValue(); if ("LABELS".Equals(mode)) { value.Text = val; } else if ("VALUES".Equals(mode)) { if (val != "0") { float valuePerc = float.Parse(val, CultureInfo.InvariantCulture.NumberFormat) * 100; value.Text = valuePerc.ToString(CultureInfo.InvariantCulture); } else { value.Text = ""; } } point.AppendChild(value); nc.AppendChild(point); pointIndex++; } nref.AppendChild(nc); if ("LABELS".Equals(mode)) { labels.AppendChild(nref); series.ReplaceChild <CategoryAxisData>(labels, series.Elements <CategoryAxisData>().FirstOrDefault()); } else if ("VALUES".Equals(mode)) { values.AppendChild(nref); series.ReplaceChild <DocumentFormat.OpenXml.Drawing.Charts.Values>(values, series.Elements <DocumentFormat.OpenXml.Drawing.Charts.Values>().FirstOrDefault()); } ; }