Are there anyway I can change what field to use in Series1 or Series2 in a Line- Barchart control in PowerApps?
Solved! Go to Solution.
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."
Yes, click on the chart and look in the advanced settings.
---
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."
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?
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."
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
184 | |
53 | |
50 | |
36 | |
35 |
User | Count |
---|---|
270 | |
91 | |
82 | |
76 | |
75 |