22
33 DocX – DocX is the community edition of Xceed Words for .NET
44
5- Copyright (C) 2009-2019 Xceed Software Inc.
5+ Copyright (C) 2009-2020 Xceed Software Inc.
66
7- This program is provided to you under the terms of the Microsoft Public
8- License (Ms-PL) as published at https://github.com/xceedsoftware/DocX/blob/master/license.md
7+ This program is provided to you under the terms of the XCEED SOFTWARE, INC.
8+ COMMUNITY LICENSE AGREEMENT (for non-commercial use) as published at
9+ https://github.com/xceedsoftware/DocX/blob/master/license.md
910
1011 For more features and fast professional support,
1112 pick up Xceed Words for .NET at https://xceed.com/xceed-words-for-net/
@@ -253,11 +254,11 @@ public Chart()
253254 /// <summary>
254255 /// Add a new series to this chart
255256 /// </summary>
256- public void AddSeries ( Series series )
257+ public virtual void AddSeries ( Series series )
257258 {
258- var seriesCount = ChartXml . Elements ( XName . Get ( "ser" , Document . c . NamespaceName ) ) . Count ( ) ;
259- if ( seriesCount >= MaxSeriesCount )
260- throw new InvalidOperationException ( "Maximum series for this chart is" + MaxSeriesCount . ToString ( ) + "and have exceeded!" ) ;
259+ var seriesCount = this . ChartXml . Elements ( XName . Get ( "ser" , Document . c . NamespaceName ) ) . Count ( ) ;
260+ if ( seriesCount >= this . MaxSeriesCount )
261+ throw new InvalidOperationException ( "Maximum series for this chart is" + this . MaxSeriesCount . ToString ( ) + "and have exceeded!" ) ;
261262
262263 //To work in Words, all series need an Index and Order.
263264 var value = seriesCount + 1 ;
@@ -339,17 +340,22 @@ public Color Color
339340 {
340341 get
341342 {
342- var colorElement = Xml . Element ( XName . Get ( "spPr" , Document . c . NamespaceName ) ) ;
343- if ( colorElement == null )
343+ var spPr = this . Xml . Element ( XName . Get ( "spPr" , Document . c . NamespaceName ) ) ;
344+ if ( spPr == null )
344345 return Color . Transparent ;
345- else
346+
347+ var srgbClr = spPr . Descendants ( XName . Get ( "srgbClr" , Document . a . NamespaceName ) ) . FirstOrDefault ( ) ;
348+ if ( srgbClr != null )
346349 {
347- var val = colorElement . Element ( XName . Get ( "solidFill" , Document . a . NamespaceName ) )
348- . Element ( XName . Get ( "srgbClr" , Document . a . NamespaceName ) )
349- . Attribute ( XName . Get ( "val" ) )
350- . Value ;
351- return Color . FromArgb ( Int32 . Parse ( val , NumberStyles . HexNumber ) ) ;
350+ var val = srgbClr . Attribute ( XName . Get ( "val" ) ) ;
351+ if ( val != null )
352+ {
353+ var rgb = Color . FromArgb ( Int32 . Parse ( val . Value , NumberStyles . HexNumber ) ) ;
354+ return Color . FromArgb ( 255 , rgb ) ;
355+ }
352356 }
357+
358+ return Color . Transparent ;
353359 }
354360 set
355361 {
@@ -358,9 +364,15 @@ public Color Color
358364 {
359365 colorElement . Remove ( ) ;
360366 }
361- colorElement = new XElement ( XName . Get ( "spPr" , Document . c . NamespaceName ) ,
362- new XElement ( XName . Get ( "solidFill" , Document . a . NamespaceName ) ,
363- new XElement ( XName . Get ( "srgbClr" , Document . a . NamespaceName ) , new XAttribute ( XName . Get ( "val" ) , value . ToHex ( ) ) ) ) ) ;
367+
368+ var colorData = new XElement ( XName . Get ( "solidFill" , Document . a . NamespaceName ) ,
369+ new XElement ( XName . Get ( "srgbClr" , Document . a . NamespaceName ) , new XAttribute ( XName . Get ( "val" ) , value . ToHex ( ) ) ) ) ;
370+
371+ // When the chart containing this series is a lineChart, the line will be colored, else the shape will be colored.
372+ colorElement = ( ( this . Xml . Parent != null ) && ( this . Xml . Parent . Name != null ) && ( this . Xml . Parent . Name . LocalName == "lineChart" ) )
373+ ? new XElement ( XName . Get ( "spPr" , Document . c . NamespaceName ) ,
374+ new XElement ( XName . Get ( "ln" , Document . a . NamespaceName ) , colorData ) )
375+ : new XElement ( XName . Get ( "spPr" , Document . c . NamespaceName ) , colorData ) ;
364376 this . Xml . Element ( XName . Get ( "tx" , Document . c . NamespaceName ) ) . AddAfterSelf ( colorElement ) ;
365377 }
366378 }
0 commit comments