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

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.

7 REPLIES 7
Community Support
Community Support

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.

@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

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.

@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

Anonymous
Not applicable

Bumping to see if the community can offer more ideas 

 

@Anonymous 

Frequent Visitor

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)

 

New Member

Old topic but in case others are stuck on this I wanted to share another solution (perhaps variation on previous solutions) that worked for my case. 

 

Assuming your chart Items property points to a collection (or involves a collection as a datasource) then adding and then removing a row of 'dummy data' on the collection will reset / deselect the selected segment of the chart. 

 

This is the example, which may need adjustment if your collection doesn't have  a column named 'Title' (in which case just replace this section with a text column that does appear in your collection.

 

This worked for me because I specifically wanted the reset / deselect to be attached to another button in the screen which performed other actions that I won't go into. Either way perhaps the principle of why it worked - that changes to the datasource or refresh of datasource triggers chart to reset 'selected' properties - may assist in hacking your solution to the challenge.

 

Collect(
    YOURCOLLECTIONNAME,
    {Title: "REMOVE"}
);
Remove(
    YOURCOLLECTIONNAME,
    LookUp(
        YOURCOLLECTIONNAME,
        Title = "REMOVE"
    )
)

 

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (19,518)