0

What I know: Shapes in python-pptx have functionality to apply transparency. What I want to do : I want my RADAR Chart to have color and transparency both.

if I apply fill to my RADAR chart there is no more support to transparency feature on the other hand applying 'format.fill.background()' remove solid fill. But I need both color and transparency. The error i get = AttributeError: 'GraphicFrame' object has no attribute 'fill'

Code is given below



#################### Transparency portion ###################
def SubElement(parent, tagname, **kwargs):
        element = OxmlElement(tagname)
        element.attrib.update(kwargs)
        parent.append(element)
        return element

def _set_shape_transparency(shape, alpha):
    """ Set the transparency (alpha) of a shape"""
    ts = shape.fill._xPr.solidFill
    sF = ts.get_or_change_to_srgbClr()
    sE = SubElement(sF, 'a:alpha', val=str(alpha))

###################################
chart_data = ChartData()
chart_data.categories = '1','2','3','4','5'
Matching_matrix=(4, 5, 5, 4, 4)
chart_data.add_series('', Matching_matrix) 
 
x, y, cx, cy = Inches(6.6), Inches(4.8), Inches(2.3), Inches(2.3)
graphic_frame = shapes.add_chart(
    XL_CHART_TYPE.RADAR_FILLED, x, y, cx, cy, chart_data
)
chart=graphic_frame.chart
chart_format=chart.plots[0].series[0].format
chart_fill=chart_format.fill
chart_fill.solid()

blueBoxFillColour = chart_fill.fore_color
blueBoxFillColour.rgb = RGBColor(0,176,240)

chart_font=chart.font 
chart_font.size=Pt(10)

_set_shape_transparency(graphic_frame,1000)
'''

FARO
  • 1
  • 2
  • Why do you say "Shapes in python-pptx have functionality to apply transparency."? What calls do you use to set the transparency of a shape? – scanny Jun 02 '21 at 17:14
  • I am using code from stackoverflow. https://stackoverflow.com/questions/38202582/how-do-i-add-transparency-to-shape-in-python-pptx – FARO Jun 02 '21 at 17:19
  • Shapes support solid fill functionality and we can make solid fill transparent. – FARO Jun 02 '21 at 17:33
  • There is no API support for transparency in `python-pptx` yet. The link you gave shows a way to use `lxml` calls to set transparency by manipulating the underlying XML directly. You would need to do something similar for the Radar chart. Note a chart has many fills; it is not a simple shape (it's actually not a shape at all). – scanny Jun 02 '21 at 18:10
  • If you want to extend the functionality of `python-pptx` then you'll probably want to be familiar with the [lxml.etree._Element](https://lxml.de/api/lxml.etree._Element-class.html) class and a few other aspects of `lxml` as that is what `python-pptx` uses to manipulate the underlying XML of the PPTX document. – scanny Jun 23 '21 at 16:12

0 Answers0