cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
espenjor
Level: Powered On

Chart - change Series

Are there anyway I can change what field to use in Series1 or Series2 in a Line- Barchart control in PowerApps?

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Level 8

Re: Chart - change Series

@espenjor 

You cannot change the field holding Series1 by a command.  The solution is to instead make a new collection to hold only the current column and update that collection everytime a control (e.g. dropdown) is changed.

 

Suppose you have a dataset that looks like this:

 

ClearCollect(
    myDataset,
   {Year:2016, SeriesA:10, SeriesB:80},
   {Year:2017, SeriesA:20, SeriesB:40},
   {Year:2018, SeriesA:40, SeriesB:20}
);

 

I would put this code in the OnVisible property of my screen to create a new collection that would serve as the Items for my Chart.  The default series is "SeriesA" in this case.

 

ClearCollect(
    chartData,
    AddColumns(myDataset,"Value",SeriesA)
);

 

Next I would build a dropdown control so my user can select what series to view.  I put this code in the Items property of the dropdown.

 

["SeriesA","SeriesB"]

 

Finally, we need to update the chartData collection whenever the dropdown selection changes.  Put this code in the OnChange property of the dropdown.  Notice that chartData always has a single column called Value no matter what.  That is how you get around not being able to programatically change the column name.

 

Switch(
    Dropdown1.Selected.Value,
    "SeriesA",ClearCollect(chartData,AddColumns(myDataset,"Value",SeriesA)),
    "SeriesB",ClearCollect(chartData,AddColumns(myDataset,"Value",SeriesB))
);

 

Now when the dropdown selection changes so will the Chart supposing you have the following properties setup in your chart like this.

 

Items: chartData
Series1: Value

 

Hopefully you can take this short lesson and adapt the techniques to your use case.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

3 REPLIES 3
mdevaney
Level 8

Re: Chart - change Series

@espenjor

Yes, click on the chart and look in the advanced settings.

 

chgChartSeries.PNG

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

espenjor
Level: Powered On

Re: Chart - change Series

I was a bit unclear in my question. I ment to ask if there are way I can change this filed (Series1) by a command /programmatically?

 

 

mdevaney
Level 8

Re: Chart - change Series

@espenjor 

You cannot change the field holding Series1 by a command.  The solution is to instead make a new collection to hold only the current column and update that collection everytime a control (e.g. dropdown) is changed.

 

Suppose you have a dataset that looks like this:

 

ClearCollect(
    myDataset,
   {Year:2016, SeriesA:10, SeriesB:80},
   {Year:2017, SeriesA:20, SeriesB:40},
   {Year:2018, SeriesA:40, SeriesB:20}
);

 

I would put this code in the OnVisible property of my screen to create a new collection that would serve as the Items for my Chart.  The default series is "SeriesA" in this case.

 

ClearCollect(
    chartData,
    AddColumns(myDataset,"Value",SeriesA)
);

 

Next I would build a dropdown control so my user can select what series to view.  I put this code in the Items property of the dropdown.

 

["SeriesA","SeriesB"]

 

Finally, we need to update the chartData collection whenever the dropdown selection changes.  Put this code in the OnChange property of the dropdown.  Notice that chartData always has a single column called Value no matter what.  That is how you get around not being able to programatically change the column name.

 

Switch(
    Dropdown1.Selected.Value,
    "SeriesA",ClearCollect(chartData,AddColumns(myDataset,"Value",SeriesA)),
    "SeriesB",ClearCollect(chartData,AddColumns(myDataset,"Value",SeriesB))
);

 

Now when the dropdown selection changes so will the Chart supposing you have the following properties setup in your chart like this.

 

Items: chartData
Series1: Value

 

Hopefully you can take this short lesson and adapt the techniques to your use case.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate 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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 136 members 5,395 guests
Please welcome our newest community members: