web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Add content/icons dyna...
Power Apps
Answered

Add content/icons dynamically in PowerApp

(0) ShareShare
ReportReport
Posted on by 543

Hi,

 

I have a form and I'm trying to simulate a simple bubble chart by plotting some values from a list (x, y and z) onto the canvas.

Since the number of values is arbitrary (from 5-15 maybe) I'd like to add the circles "programmatically" (ForAll), but I'm not sure it's currently possible?

 

Thanks

Categories:
I have the same question (0)
  • Verified answer
    davidni Profile Picture
    on at

    I wrote a blog post for you, let me know if it helps: Scatter plots in PowerApps using a Gallery control

     

     

  • JohnP Profile Picture
    543 on at

    Thanks a lot! This will definitely help!

  • Community Power Platform Member Profile Picture
    on at

    Hi, firstly, thank you for a very useful post.

     

    Apologies if this is an obvious one to resolve, but I cannot figure it out for the life of me.

     

    How do you replace the randomly generated numbers in your scattergraph? I am using a table 'fruit' with 2 columns: ID (integer) and price (float).  I have tried replacing rand() with fruit.ID and fruit.price, but this creates an 'invalid argument' error.

     

    This occurs regardless of whether the table is imported as a static excel doc or as a onedrive cloud file.

     

    Are we meant to use another approach to iomport new data?

     

    I have changed the name of the collection from 'bubbles' to 'collectionsample' in the code below.

     

    Your assistance is much appreciated-thank you 🙂

     

    UpdateContext(
     {
     minRadius: 10,
     maxRadius: 10
     }
    );
    Collect(
     Collectionsample,
     {
     index: CountRows(Collectionsample),
     x: Fruit.ID * (Gallery1.Width - maxRadius*2) + maxRadius,
     y: Fruit.Cost * (Gallery1.Height - maxRadius*2) + maxRadius,
     radius: Rand() * (maxRadius-minRadius) + minRadius,
     color: RGBA(Rand() * 255, Rand() * 255, 0, 1)
     })
    
    
    
  • davidni Profile Picture
    on at

    @Anonymous  I was using Collect(...) on my sample app to illustrate how to dynamically add bubbles by clciking a button. In your case, it sounds like your data is coming from an external data source, so you wouldn't use Collect(...). Instead, you should bind your data source directly to the Gallery. If you can change your data to have columns x, y and radius the switch should be straighforward.

    In formulas:

    Gallery1.Items = CollectionSample

    And inside the gallery template, set the Circle's X, Y properties according to your data.

     

    Hopefully this helps point you in a good direction.

  • Community Power Platform Member Profile Picture
    on at

    Hi David, many thanks for the quick reply.

     

    I've now made some progress, but I think I may have misunderstood some of the core concepts here.

     

    Firstly,  I cannot figure out where the following code in your original post is meant to be placed (unless it is hidden somewhere, or something that powerapps quietly runs in the background without the user needing to be aware):

     

    Circle1.X      = ThisItem.x-ThisItem.radius
    Circle1.Y      = ThisItem.y-ThisItem.radius-ThisItem.index*Gallery1.TemplateHeight
    Circle1.Width  = ThisItem.radius*2
    Circle1.Height = ThisItem.radius*2
    Circle1.Fill   = ThisItem.color

     

    Secondly, I tried to bind my data directly to the gallery as you described. Unfortunately, no available data fields appear on the right hand pane, even though I changed the fields to x, y and radius as you suggested.

     

    Finally, I am confused by the term 'Gallery1.Items = CollectionSample'. Surely Gallery1.Items=Fruit (since this is the table which is the data source). Unless you are refering to the approach of using a collection rather than an external data source, as per your demo?

     

    I apologise for any fundamental misunderstandings here; I am doing my best to get a grasp of what's going on! I have done my best to follow your guidance to the letter, and would really appreciate any help.

     

    Thanks anyway for the guidance provided so far 🙂

     

  • davidni Profile Picture
    on at

    @Anonymous The Gallery is one of the harder controls to grasp at first, but it is also one of the most powerful -- and not really scary once you get the hang of it.

     

    I built the sample app (attached) for you using a Fruits table (imported from Excel, original also attached) Please take some time to explore it and it may help answer some of your questions.

     

    You will see there is a big control on the screen called Gallery1. Inside it (in the gallery template) there is a circle shape called Circle1 and a label called Label1. I have wired up properties on Circle1 and Label1 so that they show values from table Fruit. On my post, when I said Circle1.X = ThisItem.x, you should read it as "assign the formula ThisItem.x to the property "X" (the horizontal position of a control) of Circle1". The screenshot attached may help you follow along.

     

    Hope this helps!

     

    Additional references and learning resources:
    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-gallery

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/add-gallery

     

  • Community Power Platform Member Profile Picture
    on at

    Hi David, many thanks once again for the help. I will look into your guidance above and get back to you with any further queries. 

     

  • Community Power Platform Member Profile Picture
    on at

    Much progress has been made so far thanks to your efforts @davidni . I was just wondering if you considered it at all possible to project a line of best fit using the data points? I'm wondering how to do this with the gallery approach 🙂



     

  • davidni Profile Picture
    on at

    @Anonymous glad you're making progress, that's always good to hear. For more advanced visualizations and data processing, you might want to consider Power BI. You can embed Power BI tiles in PowerApps, see: https://powerbi.microsoft.com/en-us/blog/power-bi-tile-in-powerapps/

     

    I'd suggest starting a separate thread for your scenario and with a relevant title. Others who did similar things in the past might be able to help you that way.

     

    Best,

    David

     

  • DBJ Profile Picture
    65 on at

    hi @davidni I'm interested in what you did in the blog post, but I'd like to also use the sample app. Is there a new location for it? it's no longer at the link mentioned in the blog post.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard