Exemplo n.º 1
0
        /// <summary>
        /// LineChart has a different structure for outline.
        /// </summary>
        public override ChartShapeProperties SetChartShapeProperties(OpenXmlCompositeElement chartSeries)
        {
            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
            Outline outline = new Outline()
            {
                Width = 28575, CapType = LineCapValues.Round
            };

            outline.Append(new SolidFill());
            outline.Append(new Round());

            chartShapeProperties.Append(new SolidFill());
            chartShapeProperties.Append(outline);
            chartShapeProperties.Append(new EffectList());
            Marker marker = new Marker();

            marker.Append(new Symbol()
            {
                Val = MarkerStyleValues.None
            });

            chartSeries.Append(chartShapeProperties);
            chartSeries.Append(marker);
            chartSeries.Append(new Smooth()
            {
                Val = false
            });

            return(chartShapeProperties);
        }
Exemplo n.º 2
0
        public OpenXmlElement GetOrCreateTextBody()
        {
            OpenXmlElement dataLabel = this.element.GetOrCreateDataLabelAdjust();

            Index index = dataLabel.GetFirstChild <Index>();
            ChartShapeProperties chartShapeProperties = dataLabel.GetFirstChild <ChartShapeProperties>();

            TextProperties textProperties = dataLabel.GetFirstChild <TextProperties>();

            if (textProperties == null)
            {
                textProperties = new TextProperties()
                {
                    BodyProperties = new Drawing.BodyProperties()
                    {
                        Wrap   = Drawing.TextWrappingValues.Square,
                        Anchor = Drawing.TextAnchoringTypeValues.Center
                    }
                    .AppendChildFluent(new Drawing.ShapeAutoFit())
                }
                .AppendChildFluent(new Drawing.ListStyle())
                .AppendChildFluent(new Drawing.Paragraph());

                if (chartShapeProperties != null)
                {
                    dataLabel.InsertAfter(textProperties, chartShapeProperties);
                }
                else
                {
                    dataLabel.InsertAfter(textProperties, index);
                }
            }

            return(textProperties);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the colour of a <see cref="BarChartSeries" /> so it matches a <see cref="SolidColorBrush" />
        /// </summary>
        /// <param name="series">The series.</param>
        /// <param name="brush">The brush.</param>
        private static void UpdateSeriesColour(this BarChartSeries series, SolidColorBrush brush)
        {
            var chartShapeProperties = series.Descendants <ChartShapeProperties>().FirstOrDefault();

            if (chartShapeProperties == null)
            {
                chartShapeProperties = new ChartShapeProperties();
                // if there's a series text then insert afterwards
                // the series title, this is the name of the column header
                var seriesText = series.Descendants <SeriesText>().FirstOrDefault();
                if (seriesText == null)
                {
                    series.InsertAt <ChartShapeProperties>(chartShapeProperties, 0);
                }
                else
                {
                    series.InsertAfter <ChartShapeProperties>(chartShapeProperties, seriesText);
                }
            }

            // Determine if the series has a SolidFill
            SolidFill seriesSolidFill = chartShapeProperties.Elements <SolidFill>().FirstOrDefault();

            if (seriesSolidFill == null)
            {
                // No fill, so create one so we can set the colour
                seriesSolidFill = new SolidFill();
                seriesSolidFill.UpdateSolidFill((SolidColorBrush)brush);
                chartShapeProperties.InsertAt(seriesSolidFill, 0);
            }
            else
            {
                seriesSolidFill.UpdateSolidFill((SolidColorBrush)brush);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the color of the series using a solidcolor brush
        /// If a null brush is supplied any color is removed so the color will be automatic
        /// </summary>
        /// <param name="series">The series.</param>
        /// <param name="brush">The brush.</param>
        /// <exception cref="ArgumentNullException">series</exception>
        public static void UpdateSeriesMarkerBrush(this OpenXmlCompositeElement series, Brush brush)
        {
            if (series == null)
            {
                throw new ArgumentNullException("series");
            }

            var marker = series.Descendants <Marker>().FirstOrDefault();

            if (marker == null)
            {
                return;
            }

            var scb = brush as SolidColorBrush;

            if (scb == null)
            {
                return;
            }

            // clear down and start again
            marker.RemoveAllChildren();

            var chartShapeProperties = new ChartShapeProperties();

            SolidFill solidFill = new SolidFill();

            StringBuilder hexString = new StringBuilder();

            hexString.Append(scb.Color.R.ToString("X"));
            hexString.Append(scb.Color.G.ToString("X"));
            hexString.Append(scb.Color.B.ToString("X"));

            RgbColorModelHex hexColour = new RgbColorModelHex()
            {
                Val = hexString.ToString()
            };

            var outlineNoFill = new Outline();

            outlineNoFill.Append(new NoFill());

            solidFill.Append(hexColour);
            chartShapeProperties.Append(solidFill);
            chartShapeProperties.Append(outlineNoFill);
            marker.Append(chartShapeProperties);
        }
Exemplo n.º 5
0
        public OpenXmlElement GetOrCreateShapeProperties()
        {
            OpenXmlElement dataLabel = this.element.GetOrCreateDataLabelAdjust();

            Index index = dataLabel.GetFirstChild <Index>();

            ChartShapeProperties chartShapeProperties = dataLabel.GetFirstChild <ChartShapeProperties>();

            if (chartShapeProperties == null)
            {
                chartShapeProperties = new ChartShapeProperties();
                dataLabel.InsertAfter(chartShapeProperties, index);
            }

            return(chartShapeProperties);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Distinct color for each bar.
        /// </summary>
        private DataPoint colorChartLines(uint lineIndex)
        {
            DataPoint dataPoint = new DataPoint();
            Index     index     = new Index()
            {
                Val = lineIndex
            };
            InvertIfNegative invertIfNegative3 = new InvertIfNegative()
            {
                Val = false
            };
            Bubble3D bubble3D1 = new Bubble3D()
            {
                Val = false
            };

            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();

            SolidFill solidFill = new SolidFill();

            solidFill.SchemeColor = new SchemeColor()
            {
                Val = SchemeColorValues.Accent1
            };
            solidFill.RgbColorModelHex = new RgbColorModelHex()
            {
                Val = ColourValues[lineIndex]
            };

            Outline outline = new Outline()
            {
                Width = 28575, CapType = LineCapValues.Round
            };

            outline.Append(new NoFill());
            outline.Append(new Round());
            chartShapeProperties.Append(solidFill);
            chartShapeProperties.Append(outline);
            chartShapeProperties.Append(new EffectList());

            dataPoint.Append(index);
            dataPoint.Append(chartShapeProperties);

            return(dataPoint);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Set display, width, color and fill of borders and data (line, bar etc.) in chart.
        /// </summary>
        public ChartShapeProperties SetChartShapeProperties(OpenXmlCompositeElement chartSeries, bool visible = true, uint colorPoints = 0)
        {
            ChartShapeProperties chartShapeProperties1 = new ChartShapeProperties();

            Outline outline1 = new Outline()
            {
                Width = 28575, CapType = LineCapValues.Round
            };
            Round round1 = new Round();

            outline1.Append(new NoFill());
            outline1.Append(round1);
            EffectList effectList1 = new EffectList();

            if (!visible)
            {
                chartShapeProperties1.Append(new NoFill());
            }

            chartShapeProperties1.Append(outline1);
            chartShapeProperties1.Append(effectList1);
            Marker marker1 = new Marker();
            Symbol symbol1 = new Symbol()
            {
                Val = MarkerStyleValues.None
            };

            marker1.Append(symbol1);
            Smooth smooth1 = new Smooth()
            {
                Val = false
            };

            chartSeries.Append(chartShapeProperties1);
            chartSeries.Append(marker1);
            chartSeries.Append(smooth1);

            for (uint i = 0; i < colorPoints; i++)
            {
                chartSeries.Append(colorChartLines(i));
            }

            return(chartShapeProperties1);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Set display, width, color and fill of borders and data (line, bar etc.) in chart.
        /// </summary>
        public virtual ChartShapeProperties SetChartShapeProperties(OpenXmlCompositeElement chartSeries)

        {
            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
            Outline outline = new Outline()
            {
                Width = 28575, CapType = LineCapValues.Round
            };

            outline.Append(new NoFill());
            outline.Append(new Round());

            chartShapeProperties.Append(outline);
            chartShapeProperties.Append(new EffectList());

            chartSeries.Append(chartShapeProperties);

            return(chartShapeProperties);
        }
Exemplo n.º 9
0
        private void FillSeriesDataPoints(OpenXmlCompositeElement seriesItem, Column dataColumn)
        {
            var seriesChartShapeProperties = seriesItem.FirstElement <ChartShapeProperties>();

            for (int rowNo = 0; rowNo < dataColumn.Data.Count; rowNo++)
            {
                if (dataColumn.Data[rowNo] != null)
                {
                    DataPoint dp = seriesItem.Elements <DataPoint>().FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == rowNo);
                    if (dp == null)
                    {
                        var dataPoint = new DataPoint();
                        DocumentFormat.OpenXml.Drawing.Charts.Index index = new DocumentFormat.OpenXml.Drawing.Charts.Index()
                        {
                            Val = new UInt32Value((uint)rowNo)
                        };
                        InvertIfNegative invertIfNegative = new InvertIfNegative()
                        {
                            Val = false
                        };
                        Bubble3D bubble3D = new Bubble3D()
                        {
                            Val = false
                        };
                        ChartShapeProperties chartShapeProperties = seriesChartShapeProperties == null ? new ChartShapeProperties() : (ChartShapeProperties)seriesChartShapeProperties.CloneNode(true);
                        dataPoint.Append(index);
                        dataPoint.Append(invertIfNegative);
                        dataPoint.Append(bubble3D);
                        dataPoint.Append(chartShapeProperties);
                        DataPoint lastDp = seriesItem.Elements <DataPoint>().LastOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value < rowNo);
                        if (lastDp != null)
                        {
                            seriesItem.InsertAfter(dataPoint, lastDp);
                        }
                        else
                        {
                            seriesItem.Append(dataPoint);
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        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;
        }
        public ChartShapeProperties Build()
        {
            var chartShapeProperties = new ChartShapeProperties();

            if (this.Options.BlackWhiteMode.HasValue)
            {
                chartShapeProperties.BlackWhiteMode = this.Options.BlackWhiteMode;
            }

            if (this.Options.FillType.HasValue)
            {
                switch (this.Options.FillType)
                {
                case FillTypes.NoFill:
                    chartShapeProperties.Append(new NoFill());

                    break;
                }
            }

            if (this.Options.HasLine)
            {
                var outlineBuilder = new OutlineBuilder(this.Options.OutlineOptions);

                chartShapeProperties.Append(outlineBuilder.Build());
            }

            if (this.Options.HasEffectList)
            {
                var effectListBuilder = new EffectListBuilder(this.Options.EffectListOptions);

                chartShapeProperties.Append(effectListBuilder.Build());
            }

            return(chartShapeProperties);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Design settings for Y axis.
        /// </summary>
        public ValueAxis SetGanttValueAxis(PlotArea plotArea, TimeSpan minSpan, TimeSpan maxSpan)
        {
            MajorGridlines       majorGridlines1       = new MajorGridlines();
            ChartShapeProperties chartShapeProperties2 = new ChartShapeProperties();
            Outline     outline2     = new Outline();
            SolidFill   solidFill2   = new SolidFill();
            SchemeColor schemeColor2 = new SchemeColor()
            {
                Val = SchemeColorValues.Accent1
            };
            Alpha alpha1 = new Alpha()
            {
                Val = 10000
            };

            schemeColor2.Append(alpha1);
            solidFill2.Append(schemeColor2);
            outline2.Append(solidFill2);
            chartShapeProperties2.Append(outline2);
            majorGridlines1.Append(chartShapeProperties2);

            return(plotArea.AppendChild <ValueAxis>(new ValueAxis(new AxisId()
            {
                Val = new UInt32Value(48672768u)
            },
                                                                  new Scaling(new Orientation()
            {
                Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>(
                    DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax)
            }, new MinAxisValue()
            {
                Val = 0
            }, new MaxAxisValue()
            {
                Val = 0.99
            }),
                                                                  new Delete()
            {
                Val = false
            },
                                                                  new AxisPosition()
            {
                Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left)
            },
                                                                  majorGridlines1,
                                                                  new MajorTickMark()
            {
                Val = TickMarkValues.None
            },
                                                                  new MinorTickMark()
            {
                Val = TickMarkValues.None
            },
                                                                  new MajorUnit()
            {
                Val = 4.1666666666666713E-2D
            },
                                                                  new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat()
            {
                FormatCode = "h:mm;@", SourceLinked = false
            },
                                                                  new TickLabelPosition()
            {
                Val = new EnumValue <TickLabelPositionValues>
                          (TickLabelPositionValues.NextTo)
            }, new CrossingAxis()
            {
                Val = new UInt32Value(48650112U)
            },
                                                                  new Crosses()
            {
                Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero)
            },
                                                                  new CrossBetween()
            {
                Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between)
            })));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Design settings for Y axis.
        /// </summary>
        public virtual ValueAxis SetValueAxis(PlotArea plotArea)
        {
            // Postavljanje Gridline-a.
            MajorGridlines       majorGridlines       = new MajorGridlines();
            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
            Outline     outline     = new Outline();
            SolidFill   solidFill   = new SolidFill();
            SchemeColor schemeColor = new SchemeColor()
            {
                Val = SchemeColorValues.Accent1
            };
            Alpha alpha = new Alpha()
            {
                Val = 10000
            };

            schemeColor.Append(alpha);
            solidFill.Append(schemeColor);
            outline.Append(solidFill);
            chartShapeProperties.Append(outline);
            majorGridlines.Append(chartShapeProperties);

            var valueAxis = plotArea.AppendChild <ValueAxis>(new ValueAxis(
                                                                 new AxisId()
            {
                Val = new UInt32Value(48672768u)
            },
                                                                 new Scaling(new Orientation()
            {
                Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>(
                    DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax)
            }),
                                                                 new Delete()
            {
                Val = !ChartProperties.AxisY
            },
                                                                 new AxisPosition()
            {
                Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left)
            },
                                                                 majorGridlines,
                                                                 SetTitle(ChartProperties.AxisYTitle),
                                                                 new NumberingFormat()
            {
                FormatCode   = ChartProperties.AxisYFormatCode,
                SourceLinked = new BooleanValue(true)
            },
                                                                 new MajorTickMark()
            {
                Val = TickMarkValues.None
            },
                                                                 new MinorTickMark()
            {
                Val = TickMarkValues.None
            },
                                                                 new TickLabelPosition()
            {
                Val = new EnumValue <TickLabelPositionValues>
                          (TickLabelPositionValues.NextTo)
            }, new CrossingAxis()
            {
                Val = new UInt32Value(48650112U)
            },
                                                                 new Crosses()
            {
                Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero)
            },
                                                                 new CrossBetween()
            {
                Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between)
            }));

            if (ChartProperties.AxisYFormatCategory == "Time")
            {
                valueAxis.Append(new MajorUnit()
                {
                    Val = getMajorUnitFromSeconds((int)yAxisValue)
                });
            }

            return(valueAxis);
        }
Exemplo n.º 14
0
        private void SetPropertiesFromLegend(OpenXmlCompositeElement seriesItem, Column dataColumn)
        {
            if (dataColumn.Legends.All(l => l == null))
            {
                return;
            }
            var dataPoints = seriesItem.Elements <DataPoint>();
            var labels     = seriesItem.FirstElement <DataLabels>();

            for (int rowNo = 0; rowNo < dataColumn.Data.Count; rowNo++)
            {
                if (dataColumn.Legends[rowNo] != null && dataColumn.Data[rowNo] != null)
                {
                    ShapeElement legend    = dataColumn.Legends[rowNo] as ShapeElement;
                    DataPoint    dataPoint = dataPoints.FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == rowNo);
                    if (legend != null) //KAJ: Actually always true if you have reached this line
                    {
                        if (dataPoint != null)
                        {
                            dataPoint.RemoveAllChildren <ChartShapeProperties>();
                            A.SolidFill          legendFill           = legend.Element.GetFill();
                            A.Outline            legendOutline        = legend.Element.GetOutline();
                            ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
                            chartShapeProperties.Append(legendFill);
                            chartShapeProperties.Append(legendOutline);
                            dataPoint.Append(chartShapeProperties);
                        }
                        if (labels != null)
                        {
                            DataLabel label = labels.Elements <DataLabel>().FirstOrDefault(p => p.Index != null && p.Index.Val != null && p.Index.Val.Value == rowNo);
                            if (label != null)
                            {
                                TextProperties labelTextProperties = label.FirstElement <TextProperties>();
                                if (labelTextProperties == null)
                                {
                                    labelTextProperties = labels.FirstElement <TextProperties>().CloneNode(true) as TextProperties;
                                    label.Append(labelTextProperties);
                                }
                                NumberingFormat labelNumberingFormat = label.FirstElement <NumberingFormat>();
                                if (labelNumberingFormat == null)
                                {
                                    labelNumberingFormat = labels.FirstElement <NumberingFormat>().CloneNode(true) as NumberingFormat;
                                    label.Append(labelNumberingFormat);
                                }
                                A.Paragraph labelParagraph      = labelTextProperties.FirstElement <A.Paragraph>();
                                var         legendRunProperties = legend.Element.GetRunProperties();
                                labelParagraph.ParagraphProperties.RemoveAllChildren <A.DefaultRunProperties>();
                                List <OpenXmlElement> list = new List <OpenXmlElement>();
                                foreach (var item in legendRunProperties.ChildElements)
                                {
                                    list.Add(item.CloneNode(true));
                                }
                                var newLabelRunProperties = new A.DefaultRunProperties(list);
                                labelParagraph.ParagraphProperties.Append(newLabelRunProperties);
                                var labelShapeProperties = label.FirstElement <ChartShapeProperties>();
                                if (labelShapeProperties != null && labelShapeProperties.FirstElement <A.NoFill>() == null)
                                {
                                    label.RemoveAllChildren <ChartShapeProperties>();
                                }
                                A.SolidFill          legendFill           = legend.Element.GetFill();
                                ChartShapeProperties chartShapeProperties = new ChartShapeProperties();
                                chartShapeProperties.Append(legendFill);
                                label.Append(chartShapeProperties);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        private void FillSeriesLabels(OpenXmlCompositeElement seriesItem, Column dataColumn)
        {
            var labels = seriesItem.FirstElement <DataLabels>();

            if (labels == null)
            {
                return;
            }
            TextProperties       defaultTextProperties       = labels.FirstElement <TextProperties>();
            ChartShapeProperties defaultChartShapeProperties = labels.FirstElement <ChartShapeProperties>();
            NumberingFormat      defaultNumberingFormat      = labels.FirstElement <NumberingFormat>();
            ShowLegendKey        defaultShowLegendKey        = labels.FirstElement <ShowLegendKey>();
            ShowValue            defaultShowValue            = labels.FirstElement <ShowValue>();
            ShowCategoryName     defaultShowCategoryName     = labels.FirstElement <ShowCategoryName>();
            ShowSeriesName       defaultShowSeriesName       = labels.FirstElement <ShowSeriesName>();
            ShowPercent          defaultShowPercent          = labels.FirstElement <ShowPercent>();
            ShowBubbleSize       defaultShowBubbleSize       = labels.FirstElement <ShowBubbleSize>();
            ShowLeaderLines      defaultShowLeaderLines      = labels.FirstElement <ShowLeaderLines>();
            DLblsExtension       defaultDLblsExtension       = labels.FirstElement <DLblsExtension>();

            for (int rowNo = 0; rowNo < dataColumn.Data.Count; rowNo++)
            {
                if (dataColumn.Data[rowNo] != null)
                {
                    DataLabel dl = labels.Elements <DataLabel>().FirstOrDefault(l => l.Index != null && l.Index.Val != null && l.Index.Val.Value == rowNo);
                    //if (dl != null)
                    //{
                    //    Delete delete = dl.FirstElement<Delete>();
                    //    if (delete == null || !delete.Val)
                    //    {
                    //        var tp = dl.FirstElement<TextProperties>();
                    //        if (tp != null)
                    //        {
                    //            textProperties = tp.CloneNode(true) as TextProperties;
                    //        }
                    //        labels.RemoveChild<DataLabel>(dl);
                    //        dl = null;
                    //    }
                    //}
                    if (dl == null)
                    {
                        var newDataLabel = new DataLabel();
                        DocumentFormat.OpenXml.Drawing.Charts.Index index = new DocumentFormat.OpenXml.Drawing.Charts.Index()
                        {
                            Val = new UInt32Value((uint)rowNo)
                        };
                        newDataLabel.Index = index;
                        if (defaultNumberingFormat != null)
                        {
                            newDataLabel.Append(defaultNumberingFormat.CloneNode(true));
                        }
                        if (defaultChartShapeProperties != null)
                        {
                            newDataLabel.Append(defaultChartShapeProperties.CloneNode(true));
                        }
                        if (defaultTextProperties != null)
                        {
                            newDataLabel.Append(defaultTextProperties.CloneNode(true));
                        }
                        newDataLabel.Append(defaultShowLegendKey.CloneNode(true));
                        newDataLabel.Append(defaultShowValue.CloneNode(true));
                        newDataLabel.Append(defaultShowCategoryName.CloneNode(true));
                        newDataLabel.Append(defaultShowSeriesName.CloneNode(true));
                        newDataLabel.Append(defaultShowPercent.CloneNode(true));
                        newDataLabel.Append(defaultShowBubbleSize.CloneNode(true));
                        if (defaultShowLeaderLines != null)
                        {
                            newDataLabel.Append(defaultShowLeaderLines.CloneNode(true));
                        }
                        if (defaultDLblsExtension != null)
                        {
                            newDataLabel.Append(defaultDLblsExtension.CloneNode(true));
                        }
                        DataLabel lastDataLabel = labels.Elements <DataLabel>().LastOrDefault(l => l.Index != null && l.Index.Val != null && l.Index.Val.Value < rowNo);
                        if (lastDataLabel != null)
                        {
                            labels.InsertAfter(newDataLabel, lastDataLabel);
                        }
                        else
                        {
                            labels.InsertAt(newDataLabel, 0);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the color of the series using a solidcolor brush
        /// If a null brush is supplied any color is removed so the color will be automatic
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="brush">The brush.</param>
        public static void UpdateLineBrush(this OpenXmlCompositeElement line, Brush brush)
        {
            if (line == null)
            {
                return;
            }

            // If we have a BarChart, we really want tp update the SolidFill (not the Outline.SolidFill)
            BarChartSeries barChartSeries = line as BarChartSeries;

            if (barChartSeries != null)
            {
                // For BarCharts, we update the SolidFill
                barChartSeries.UpdateSeriesColour((SolidColorBrush)brush);
            }
            else
            {
                // Update the Outline.SolidFill + set the SolidFill to the same colour
                var chartShapeProperties = line.Descendants <ChartShapeProperties>().FirstOrDefault();

                if (brush == null && !(brush is SolidColorBrush))
                {
                    if (chartShapeProperties != null)
                    {
                        line.RemoveChild <ChartShapeProperties>(chartShapeProperties);
                    }
                    return;
                }

                // the series title, this is the name of the column header
                var seriesText = line.Descendants <SeriesText>().FirstOrDefault();

                if (chartShapeProperties == null)
                {
                    chartShapeProperties = new ChartShapeProperties();
                    // if there's a series text then insert afterwards
                    if (seriesText == null)
                    {
                        line.InsertAt <ChartShapeProperties>(chartShapeProperties, 0);
                    }
                    else
                    {
                        line.InsertAfter <ChartShapeProperties>(chartShapeProperties, seriesText);
                    }
                }

                var outline = chartShapeProperties.Descendants <Outline>().FirstOrDefault();
                if (outline == null)
                {
                    outline = new Outline();
                    chartShapeProperties.InsertAt(outline, 0);
                }

                var outlineSolidFill = outline.Descendants <SolidFill>().FirstOrDefault();
                if (outlineSolidFill == null)
                {
                    outlineSolidFill = new SolidFill();
                    outline.Append(outlineSolidFill);
                }

                // Update the fill with the supplied brush colour
                outlineSolidFill.UpdateSolidFill((SolidColorBrush)brush);

                // Clones the OutlineSolidFill as the SolidFill of the series...
                var solidFill = chartShapeProperties.GetFirstChild <SolidFill>();
                if (solidFill != null)
                {
                    chartShapeProperties.RemoveChild(solidFill);
                }
                chartShapeProperties.InsertAt(outlineSolidFill.CloneNode(true), 0);
            }
        }