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

3 REPLIES 3
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."

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,548)