cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tianaranjo
Continued Contributor
Continued Contributor

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
CarlosFigueira
Power Apps
Power Apps

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
CarlosFigueira
Power Apps
Power Apps

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

@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
Continued Contributor
Continued Contributor

@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!

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
Continued Contributor
Continued Contributor

@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.

 

 

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
User Groups Public Preview

Join us for our User Group Public Preview!

Power Apps User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (44,932)