cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
tianaranjo
Level 8

HTML Shape (not displaying)

Greetings:

 

I would like to add a 'shape' object to my HTML Text control.  I have written:

"<svg width='400' height='110' 
    rect width= "& Line1.Width &"
    height='100' 
    style ='fill:#903300 
    stroke-width:3 
    stroke:rgb(0,0,0)'
</svg>" 

I do not have any errors on my side; yet, nothing appears in the HTML Text box.

Any thoughts?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: HTML Shape (not displaying)

The HTML Text element doesn't allow some tags which can potentially execute code and therefore be used for security exploits, and <svg> is one of them.

 

If you want to dynamically generate a <svg> element in PowerApps, you can use an image, with the data uri scheme, as shown in the attached app. The idea is to create an expression that is a valid <svg> element, and use it as the value for the image URL, as in the example below.

"data&colon;image/svg+xml;utf-8," &
"<svg xmlns='http://www.w3.org/2000/svg'>" &
"<rect x='25' y='25' width='" & sldRectWidth.Value & "' height='" & sldRectHeight.Value & "' " &
"style='fill:#903300; stroke-width:3; stroke:rgb(0,0,0)' />" &
"</svg>" 

Notice that your example isn't a valid SVG element. The <rect> element must be a child element of the <svg> element, not an attribute.

View solution in original post

6 REPLIES 6
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: HTML Shape (not displaying)

The HTML Text element doesn't allow some tags which can potentially execute code and therefore be used for security exploits, and <svg> is one of them.

 

If you want to dynamically generate a <svg> element in PowerApps, you can use an image, with the data uri scheme, as shown in the attached app. The idea is to create an expression that is a valid <svg> element, and use it as the value for the image URL, as in the example below.

"data&colon;image/svg+xml;utf-8," &
"<svg xmlns='http://www.w3.org/2000/svg'>" &
"<rect x='25' y='25' width='" & sldRectWidth.Value & "' height='" & sldRectHeight.Value & "' " &
"style='fill:#903300; stroke-width:3; stroke:rgb(0,0,0)' />" &
"</svg>" 

Notice that your example isn't a valid SVG element. The <rect> element must be a child element of the <svg> element, not an attribute.

View solution in original post

tianaranjo
Level 8

Re: HTML Shape (not displaying)

@CarlosFigueira - Thank you for your reply.  After originally posting, I found the thread below; it describes what you proposed. This brings me to my next question, for the Image Data URI scheme, can I refer to objects (shapes) within the app? Basically, I have 4 rectangles that I am using to form a 'Gantt' chart.  Can I use the blobURL to:

  1. Compile the 'shapes' into 1 image control as you described below? 

 

(The link below describes in more detail what I am trying to acheive and includes an image).  

 

https://powerusers.microsoft.com/t5/Creating-Apps/Bug-SVG-crashes-PowerApps/m-p/150066#M4108

Thanks again!

 

Edit - following my post here, I opened the app you sent and I (think) I see how I can acheive this.  This is greatly appreciated; I'm going to try it now.

tianaranjo
Level 8

Re: HTML Shape (not displaying)

@CarlosFigueira Can you also advicse on how to take the image and inject it into HTML Text to send in an email?  I have tried 100 ways under the sun with no luck.

 

Thank you Sir!

PowerApps Staff tahoon
PowerApps Staff

Re: HTML Shape (not displaying)

There is no easy way to extract an image of multiple rectangles. PowerApps is not great at data visualizations; Power BI is a more appropriate tool for Gantt charts. You might want to check if your organization's plan includes Power BI.

 

Here is one possible way to construct a SVG of multiple rectangles. It is complicated and assumes familiarity with SVG elements.

  1. Get the X and Y coordinates of the rectangles
  2. Get the width and height of the rectangles
  3. Get the fill colors and other styles required of the rectangles
  4. Determine the width and height of the desired viewbox. The viewbox is the container for the rectangles. This should be big enough to show all the rectangles.
  5. Create a SVG, with each rectangle in a <rect> element. The goal is to get a SVG that looks like this.

 

<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <rect x="0" y="0" width="100" height="10" fill="red" />
  <rect x="30" y=20" width="50" height="10" fill="#00ff00" />
</svg>

Note that a ShapeControl's X and Y coordinates is measured from the top left of the screen, so you have to do some math if the viewbox does not start on the top left corner.

tianaranjo
Level 8

Re: HTML Shape (not displaying)

@tahoon Thank you; I have the SVG (image) functioning as I  would like.  My issue now is 'how to reference the image url' in the HTML text.  I found the Blob URL for the object but am not sure how to integrate that in the HTML text that.

 

 

PowerApps Staff tahoon
PowerApps Staff

Re: HTML Shape (not displaying)

Blob URLs cannot be "exported". It only works in a particular's user browser for the current session. If the goal is to create an image that can be shared in an email, the only ways I can think of are to construct a SVG within PowerApps like described above, or use some service to construct an image based on the chart parameters.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 327 members 1,495 guests
Please welcome our newest community members: