none
Loosing style and color while updating data in a piechart with openxml RRS feed

  • Question


  • I´m changing the data of a set of existing charts inside my word document using openxml sdk

    My code works well for LineChart and BarChart but for PieChart it lost the Style and Color for the graph. The problem is that my piechart became with diff colors compared with the others chart of rest of my document. Here is a part of my code that works well for the others graphs but for pie charts lost style and color of the graph

    ###Code###

    DocumentFormat.OpenXml.Drawing.Charts.PieChart chart

    chart.RemoveAllChildren<PieChartSeries>();    //removes the current data from the chart

    PieChartSeries chartSeries = chart.AppendChild<PieChartSeries>(new PieChartSeries(new Index() { Val = new UInt32Value(i) }, new Order() { Val = new UInt32Value(i) }, new SeriesText(new NumericValue() { Text = key }), teste));   //this start to create new info to fil the graph    

    ###Code###

    I check the word document with “Open XML SDK 2.5 Productivity Tool for Microsoft Office” and for the piechart it does not have the itens /word/chart/colors.xml and /word/chart/style.xml

    I´m using office 2013

    Any help would be great.

    Thanks 




    Friday, October 4, 2013 7:35 PM

All replies

  • Hi Felipe

    My suggestion would be to view the basic XML of the original pie chart in the Productivity Tool, before you run your code and look where/how the color information is stored in the Open XML.

    If I insert a default pie chart there's a <c:VaryColors> element as the first child of the c:pieChart element. This tells the chart engine to assign a different basic color to each series.

    What is your original pie chart using to define the colors?


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, October 12, 2013 12:26 PM
    Moderator
  • Hi Cindy , Thanks for your answer. 

    I just check the <c:VaryColors> with the openxml comparation tool and varycolors is presents in the output and input document and they are the same   <c:varyColors val="1"/>. My issue is not because the colors are the same(varycolors=0) the issue is because the colors does not follow my set of color that the columns charts which means that i end with collumncharts and piecharts using a different set of colors. 

    I also add my example files http://www.mediafire.com/download/oxnr74ejnpd4vcf/word_files.zip  (template used and the output file) if you want to look at original files.

    The original color i set using the word app itself and it is the second color set of colors in the pallet of word app.

    About my code i think that is very strange it work for collumnchart and not work for piechart. 



    Monday, October 14, 2013 1:58 PM
  • Well, as far as I can tell, individually set colors of the pie chart are recorded in this element, in the chart XML file:

    <c:dPt>
      <c:idx val="0"/>
      <c:bubble3D val="0"/>
      <c:spPr>
       <a:solidFill>
        <a:srgbClr val="FFFF00"/>
       </a:solidFill>
      </c:spPr>
    </c:dPt>

    The c:idx val references the c:pt idx="0" under c:cat

    The srgbClr value can refer to a color in the theme or an individually selected color.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, October 16, 2013 5:09 PM
    Moderator
  • Hi Cindy, 

    I take a look near the code that you have point and i found some diff between my word documents. 

    This is the code for the doc that the color is correct

         <c:dPt>
          <c:idx val="1"/>
          <c:bubble3D val="0"/>
          <c:spPr>
           <a:blipFill>         
            <a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId3">
             <a:duotone>
              <a:schemeClr val="accent3">
               <a:shade val="74000"/>
               <a:satMod val="130000"/>
               <a:lumMod val="90000"/>
              </a:schemeClr>
              <a:schemeClr val="accent3">
               <a:tint val="94000"/>
               <a:satMod val="120000"/>
               <a:lumMod val="104000"/>
              </a:schemeClr>
             </a:duotone>
            </a:blip>
            <a:tile tx="0" ty="0" sx="100000" sy="100000" flip="none" algn="tl"/>
           </a:blipFill>
           <a:ln>
            <a:noFill/>
           </a:ln>
           <a:effectLst>
            <a:innerShdw blurRad="25400" dist="12700" dir="13500000">
             <a:srgbClr val="000000">
              <a:alpha val="45000"/>
             </a:srgbClr>
            </a:innerShdw>
           </a:effectLst>
          </c:spPr>
         </c:dPt>

    And this the is the code for the word that is not correct

          <c:spPr>
           <asolidFill>
            <a:schemeClr val="accent3"/>
           </asolidFill>
           <a:ln>
            <a:noFill/>
           </a:ln>
           <a:effectLst>
           </a:effectLst>
          </c:spPr>

    Is there an way to set the colors?

    Friday, October 18, 2013 12:46 PM
  • Hi Felipe

    You're going to have to do some detective work, all we can do is try to point you in the direction you need to go.

    My recommendation to you would be to do some experimenting with pie charts as a user, then look at the results. I think, if you click on each pie slice and assign a color that's NOT a theme, you'll get Office Open XML that shows how this is done for a pie chart. It will probably look like the code I posted in my last reply, with a <c:dPt> element for each pie slice. Experimenting will confirm that, or not.

    If it turns out this is the case, then you assign colors by creating these elements with child elements for each slice to which you want to assign a given color.

    On the other hand, if you want to use a theme's colors, which is what the pie chart is doing by default, then you use code like what you posted in your last message.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 18, 2013 5:50 PM
    Moderator