cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
espenjor
Helper II
Helper II

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

@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

4 REPLIES 4
mdevaney
Super User
Super User

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

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?

 

 

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

TimBarnes97
Frequent Visitor

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. :')

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,274)