Unable to change font color in chart axis - fixed by changing order of solidFill and latin XML tags

Issue #939 resolved
Edd
created an issue

Hi,

Trying to change the color of the chart axis by changing the solidFill parameter like so:

c1 = LineChart()

normal_font = Font(typeface='Arial')
cp_text = CharacterProperties(latin=normal_font, sz=900, b=False, solidFill='FFC000')
c1.x_axis.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp_text), endParaRPr=cp_text)])
c1.y_axis.txPr =  RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp_text), endParaRPr=cp_text)])

The code changes font type and size, but does not change the color. I've looked into XML generated part for y_axis:

<a:pPr>
   <a:defRPr b="0" sz="900">
      <a:latin typeface="Arial"/>
      <a:solidFill>
         <a:srgbClr val="FFC000"/>
      </a:solidFill>
   </a:defRPr>
</a:pPr>

I discovered that if the order between tags solidFill and latin is changed, it works! The format is still changed to correct font and size:

<a:pPr>
   <a:defRPr b="0" sz="900">
      <a:solidFill>
         <a:srgbClr val="FFC000"/>
      </a:solidFill>
      <a:latin typeface="Arial"/>
   </a:defRPr>
</a:pPr>

Would it be possible to have a quick fix on this?

Thank you,

Edd

Comments (5)

  1. Edd reporter

    I made it work in my local version by changing the order in __elements__ parameter of class CharacterProperties in openpyxl\drawing\text.py:

    class CharacterProperties(Serialisable):
    
    __elements__ = ('ln', 'highlight', 'ea', 'cs', 'sym',
                        'hlinkClick', 'hlinkMouseOver', 'rtl', 'noFill', 'solidFill', 'gradFill',
                        'blipFill', 'pattFill', 'grpFill', 'effectLst', 'effectDag', 'uLnTx',
                        'uLn', 'uFillTx', 'uFill', 'latin')
    

    but I don't know if this breaks anything else...

  2. Log in to comment