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

Reset Chart after OnSelect()

I am using the Bar Chart OnSelect() event to change a filter on a list.  The problem is once you select a chart bar, it stays selected and future clicks on the same bar do not trigger an event.

6 REPLIES 6
Community Support Team
Community Support Team

Re: Reset Chart after OnSelect()

Hi @TiredOldCoder ,

Could you please share a bit more about your issue?

Could you please show more details about the Filter formula you typed within the OnSelect property of the Bar Chart control?

Further, do you apply the result your Filter formula returned into your Bar Chart?

 

Based on the needs that you mentioned, I suppose that you want to reset your Bar Chart when you click the same bar second time, is it true?

I have made a test on my side, I think a global variable could achieve your needs. I have made a test on my side, please take a try with the following workaround:2.JPG

 

3.JPG

Set the OnStart property of the App control to following:

ClearCollect(Records, ColumnChartSample);Set(Index, 1)

On your side, you should type:

ClearCollect(Records, 'YourList'); Set(Index, 1)

Set the Items property of the Column Chart (ColumnChart1) to following:

Records

Set the OnSelect property of the Column Chart to following:

If(
    Index=2,
    ClearCollect(Records, ColumnChartSample); Set(Index, Index-1),
    ClearCollect(Records, Filter(ColumnChartSample, Area = ColumnChart1.Selected.Area)); Set(Index, Index+1)
)

On your side, you should type:

If(
    Index = 2,
    ClearCollect(Records, 'YourList'); Set(Index,Index-1),
    ClearCollect(Records, Filter('YourList', Filtercolumn = ColumnChart1.Selected.FilterColumn)); Set(Index, Index+1)
)

Please check the following GIF screenshot for more details:Test.gif

please take a try with above solution, then re-load your app, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TiredOldCoder
Level: Powered On

Re: Reset Chart after OnSelect()

@v-xida-msft,

You understand the problem peefectly.  Question: where is Index used on the control? Also, there are times when I show only 1 Bar because the others values are 0.  Is it possible to set the Index to 0 so none of the bars are selected?

 

Bill

Community Support Team
Community Support Team

Re: Reset Chart after OnSelect()

Hi @TiredOldCoder ,

Actually, the Index variable within my app is used to record the how many times you click the Column Chart in your app (I assume that, when you click Chart first time, filter your Chart bars. Then when you click the second time, reset your Bar charts to display all Bar charts).

 

Yeah, you could also consider initialize the Index variable to 0 within the OnStart property of the App control. 

Set the OnSelect property of the Column Chart to following:

If(
    Index = 1,
    ClearCollect(Records, ColumnChartSample); Set(Index, Index-1),
    ClearCollect(Records, Filter(ColumnChartSample, Area = ColumnChart1.Selected.Area)); Set(Index, Index+1)
)

On your side, you should type:

If(
    Index = 1,
    ClearCollect(Records, 'YourList'); Set(Index,Index-1),    /* <-- Index: 1 -> 0    display all bar charts in your Column Chart control */
    ClearCollect(Records, Filter('YourList', Filtercolumn = ColumnChart1.Selected.FilterColumn)); Set(Index, Index+1)   /* Index: 0 -> 1 */
)

 

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TiredOldCoder
Level: Powered On

Re: Reset Chart after OnSelect()

@v-xida-msft,

So basically you're telling me the only way to reset the charts is to update the associated items collection?  This is a little cumbersome because I have 6 charts displaying different aspects of the data statistics and they do not change. Clicking on them changes the gallery items with a new filtered list.  If I understand this correctly, my only recourse would be to add to each chart's OnSelect event code to reset the other five charts items collection.

Surely there must be a better way.  I really do like PowerApps, especially the cross platform capability but the API is not advanced enough to build really sophisticated applications - the developer ends up using work-arounds and non-obvious, extensive code to get there.

v/r,

Bill

Administrator
Administrator

Re: Reset Chart after OnSelect()

Bumping to see if the community can offer more ideas 

 

@TopShelf-MSFT 

Angry_Neutron
Level: Power Up

Re: Reset Chart after OnSelect()

I found the best way to achieve this is to temporarily set the DisplayMode of the Chart to View, and then change it back to Edit, the selection will be removed and you will be able to select the same Chart column again to trigger the OnSelect function again.

 

This can be done in the same OnSelect formula as the chart itself.

 

OnSelect
UpdateContext({ChartFlash:1});
'whatever action you want triggered' ; UpdateContext({ChartFlash:0})

 

DisplayMade

If(ChartFlash=0,DisplayMode.Edit, DisplayMode.View)

 

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: 90 members 5,261 guests
Please welcome our newest community members: