Sub topic 8
Pattern: switching between a chart and a table
This chapter assumes you can create visuals and slicers, use the Selection pane to hide and show visuals, and create bookmarks with the Data, Display, and Current page options. It builds on the show/hide panel pattern. The mechanics are the same, but here two visuals take turns in the same space.
What the pattern does
A view switch lets the reader choose how to see the same data. One button shows a chart, and another shows a table in the same position. Only one of the two visuals is visible at a time.
This is useful when a page has limited space. The chart gives a quick overview, and the table gives exact values for readers who want them. It also keeps the page from getting crowded.
The pattern has three parts:
- Two visuals stacked at the same position, one chart and one table.
- Two bookmarks. One records "chart visible, table hidden" and the other records the reverse.
- Two buttons. Each one applies one of the bookmarks.
Step 1: Build and stack the visuals
Create a clustered column chart, for example Sales by Category. Then create a table with the same fields, for example Category and Sales. Give both the same size and position. You can set exact values under Format > General > Properties > Size and Position, so that switching between them does not make the layout jump.
Add the two buttons above or beside the stack. A common choice is the built-in button shapes with icons, such as a bar chart icon and a table icon. Use the same size for both, and put them close to each other so they read as one control.
Step 2: Name things in the Selection pane
Open View > Selection pane. Rename the objects so the list is readable:
Chart - Sales by CategoryTable - Sales by CategoryBtn - Show chartBtn - Show table
Names matter here. Both visuals sit at the same position, so on the canvas you cannot easily click the one underneath. The Selection pane lets you pick either one, and it is also the place where you set visibility.
Step 3: Create the two bookmarks
For the first bookmark:
- In the Selection pane, hide the table by clicking its eye icon. The chart should be the only one visible.
- Open View > Bookmarks and select Add.
- Rename the bookmark
Chart view.
For the second bookmark:
- In the Selection pane, show the table and hide the chart.
- Select Add again.
- Rename the bookmark
Table view.
Now set the capture options for both bookmarks. Select the three dots next to each bookmark and look at the options:
| Option | Setting for this pattern | Reason |
|---|---|---|
| Data | Off | The switch should not change or reset slicer and filter selections. |
| Display | On | Visual visibility is part of Display, and this is what the pattern needs. |
| Current page | On | The bookmark stays on the page where you created it. |
| Selected visuals | Optional | See the callout below. |
Step 4: Assign the button actions
Select the first button. In the Format pane, open Action and turn it on. Set Type to Bookmark and choose Chart view as the Bookmark. Repeat for the second button with Table view.
In Desktop, use Ctrl+click on a button to test it. You can also switch to reading view if you prefer to test without the key modifier.
Add a tooltip to each button under Action > Tooltip, such as "Show chart" and "Show table". Screen reader users and mouse users both benefit from it. Also fill in alt text for each button under General > Alt text, because a button with only an icon has no readable label otherwise.
Showing which view is active
A reader should be able to tell which view they are in. There are two ways to do this.
Option A: swap button appearance with bookmarks
Make the active button look selected. For example, give each button a "selected" look and an "unselected" look by creating four buttons: two for each view. In the Chart view bookmark, show the selected chart button and the unselected table button, and hide the other two. In the Table view bookmark, do the reverse. Because Display is captured, each bookmark brings the right buttons with it.
This takes more objects to manage, so naming them clearly in the Selection pane becomes essential.
Option B: use the pressed state
Buttons have a Pressed state under Style. You can style it to look highlighted. This is simpler, but the pressed look appears only while the reader is clicking. It does not stay on to show the active view. For a persistent indicator, use Option A, or add a text label that is shown in each bookmark, such as "Viewing: Table".
Slicers and cross-filtering still work
Because Data is off, slicers keep working across both views. Suppose the reader selects Category = Bikes in a slicer, then switches from chart to table. The table shows only Bikes, because both visuals respond to the same filter context.
A hidden visual still exists on the page and still responds to filters. Hiding does not remove it from the page. It only stops it from being shown. This has two practical consequences:
- Both visuals send queries when the page loads, so a very heavy table can slow the page even when it is hidden.
- Selecting data points in the visible chart can cross-filter other visuals as usual. The hidden table is filtered too, so it is already up to date when the reader switches.
Edge cases and common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Switching views clears the slicer selection | Data is on in the bookmark | Turn Data off in both bookmarks. |
| A new visual added later appears in both views | The bookmark was created before the visual existed, so it has no stored visibility for it | Update both bookmarks after adding or changing visuals. |
| The wrong visual shows after the switch | The bookmark was created with the wrong visibility | Set the visibility in the Selection pane, then choose Update in the bookmark menu. |
| Clicking does nothing in Desktop | The click was made without Ctrl | Ctrl+click in editing view, or test in reading view. |
| The button does not respond in the service | The bookmark was deleted or renamed, or the action is turned off | Check the Action settings and the bookmark list. |
| Layout shifts between views | The two visuals have different sizes or positions | Set identical size and position values. |
Remember that a bookmark stores visibility at the moment you create or update it. If you change the layout later, such as moving a visual or adding a title, you need to select Update on each bookmark. Update records the current state again, using the capture options you have set.
Extending the pattern
You can switch more than two views. For three views, such as chart, table, and map, create three bookmarks and three buttons, and make each bookmark hide the other two visuals.
If you want a single control that works like a tab strip, use a bookmark navigator visual instead of separate buttons. It builds one button per bookmark and highlights the active one automatically. To limit it to these two bookmarks, put Chart view and Table view in a bookmark group and point the navigator at that group. Chapter details on groups and the navigator come later in this tutorial.
Accessibility and testing
- Check the tab order in the Selection pane or under General > Tab order, so that keyboard users reach the chart button before the table button, and the visuals in a sensible sequence.
- Make sure hidden visuals do not trap keyboard focus. Visuals that are hidden through a bookmark are skipped by keyboard navigation in the report.
- Do not rely on color alone to show the active view. Use text or an icon change as well.
- Test both views with a slicer set to one value, then to no value, then to a value with no data. The table and chart should both handle an empty result gracefully.
Exercise
You built Chart view and Table view bookmarks, and the buttons work. But when a reader picks Category = Bikes in a slicer and then clicks the Table button, the slicer resets to All. What is the most likely cause, and how do you fix it?
Show answer
The bookmarks were created with the Data option on, so applying them restores the slicer state saved at creation time. Open the bookmark menu for each bookmark, turn Data off, and leave Display on. Test again, and use Update if you changed visibility after creating the bookmark.
Exercise
Why does the pattern use two bookmarks that each hide one visual, instead of one bookmark that toggles visibility?
Show answer
A bookmark stores a fixed state and does not flip anything. Applying a bookmark always sets the same visibility. So each view needs its own bookmark that records which visual is visible and which is hidden.