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."
Hi Espenjor,
I know there has already been an accepted solution but I think I actually happened upon a workaround for this. I had a chart which the Data source was a filter function which highlighted people in particular O365 groups. Of course, as it was a function datasource it would not allow me to edit the labels, series etc.
The way I worked around this was to actually copy the Chart datasource function, delete the chart entirely, re-add a fresh chart with the basic property set to the datasource which appears in your function, which allows you to change the series. Change them to what you want making sure they are all in there somewhere even if not using them, then paste back in the formula to the datasource. For me, it changed the data but kept the series order which is exactly what I wanted.
Then, don't ever touch the chart again in fear of messing it up again. :')
User | Count |
---|---|
257 | |
108 | |
90 | |
51 | |
44 |