The bar color changes in the diagram.

Issue #1233 open
Magnus Schieder created an issue

Hello, I got a file where openpyxl (v2.6.1) unfortunately changes the bar color in the charts. I couldn't create a charts myself with the same effects.

After reading and writing there are two places where the idx values are wrong.

1)

original/xl/charts/chart1.xml

     <c:barChart>                                                               
        <c:barDir val="bar"/>                                                    
        <c:grouping val="percentStacked"/>                                       
        <c:varyColors val="0"/>                                                  
        <c:ser>                                                                  
          <c:idx val="1"/>                                                       
          <c:order val="0"/>                                                     
          <c:tx>                                                                 
            <c:strRef>

edited/xl/charts/chart1.xml

      <barChart>                                                                 
        <barDir val="bar"/>                                                      
        <grouping val="percentStacked"/>                                         
        <varyColors val="0"/>                                                    
        <ser>                                                                    
          <idx val="0"/>                                                         
          <order val="0"/>                                                       
          <tx>                                                                   
            <strRef>

2)

original/xl/charts/chart1.xml

        </c:ser>                                                                 
        <c:ser>                                                                  
          <c:idx val="2"/>                                                       
          <c:order val="1"/>                                                     
          <c:tx>                                                                 
            <c:strRef>

edited/xl/charts/chart1.xml

      </ser>                                                                   
        <ser>                                                                    
          <idx val="1"/>                                                         
          <order val="1"/>                                                       
          <tx>                                                                   
            <strRef>

original:

original.PNG

edited:

edited.PNG

Comments (7)

  1. CharlieC

    Thanks for the report and the sample file. It looks like the chart style isn't being preserved and by default openpyxl doesn't set one.

  2. CharlieC

    A closer look at this suggests that this is comination of the introduction of colour palettes (in Excel 2013, I think) and the index of the data series. There is no documented correlation between the index and the colour in the OOXML specification.

  3. Magnus Schieder reporter

    Hello, thanks for the patch.

    In this chart the colors are unfortunately still mixed up.

    original /xl/charts/chart1.xml

            <c:ser>    
              <c:idx val="0"/>
              <c:order val="1"/>
              <c:tx>
                <c:strRef>
    

    before the patch /xl/charts/chart1.xml

            <ser>
              <idx val="1"/>
              <order val="1"/>
              <tx>
                <strRef>
    

    after the patch /xl/charts/chart1.xml

            <ser>
              <idx val="1"/>
              <order val="1"/>
              <tx>
                <strRef>
    

    original:

    original2.PNG

    edited:

    edited2.PNG

  4. CharlieC

    Ugh! This is no fun at all. Basically Excel should not be mapping the colours so explicitly as this behaviour is not defined anywhere.

  5. Log in to comment