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

Add content/icons dynamically in PowerApp

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

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff davidni
Power Apps Staff

Re: Add content/icons dynamically in PowerApp

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

 

 

David Nissimoff [MSFT] ** PowerApps Staff

View solution in original post

9 REPLIES 9
Power Apps Staff davidni
Power Apps Staff

Re: Add content/icons dynamically in PowerApp

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

 

 

David Nissimoff [MSFT] ** PowerApps Staff

View solution in original post

JohnP
Level 8

Re: Add content/icons dynamically in PowerApp

Thanks a lot! This will definitely help!

MaxDonen
Level: Powered On

Re: Add content/icons dynamically in PowerApp

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)
  })


Power Apps Staff davidni
Power Apps Staff

Re: Add content/icons dynamically in PowerApp

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

David Nissimoff [MSFT] ** PowerApps Staff
MaxDonen
Level: Powered On

Re: Add content/icons dynamically in PowerApp

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 🙂

 

Power Apps Staff davidni
Power Apps Staff

Re: Add content/icons dynamically in PowerApp

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

 

David Nissimoff [MSFT] ** PowerApps Staff
MaxDonen
Level: Powered On

Re: Add content/icons dynamically in PowerApp

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. 

 

MaxDonen
Level: Powered On

Re: Add content/icons dynamically in PowerApp

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 🙂



 

Power Apps Staff davidni
Power Apps Staff

Re: Add content/icons dynamically in PowerApp

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

 

David Nissimoff [MSFT] ** PowerApps Staff

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,533)