Creating customizable chart components in Figma
As designers, we sometimes need to use data visualizations in our designs. When we do, we want to give a realistic representation of information in different scenarios. This isn’t easily achieved with components and might often be done locally in the file, meaning it isn’t always possible to update from a design system library.
Last year, IBM’s Carbon design team shared a post that sparked my curiosity. Could it be possible to have a data visualization component that can be adjusted by designers without detaching?
I look forward to seeing what the Carbon team makes public, but in the meantime here’s how I’ve been inspired to try this in my own work.
The key: a resizer component 🔑
What’s a resizer component? It might look like an empty box, but don’t let that fool you. This simple but powerful component works by increasing or decreasing the gap between two frames using auto layout. When a resizer is nested in a component, it unlocks the ability to adjust sizes without the need to detach instances.
To create a resizer, just make a component with two empty frames and then apply auto layout to control the gap between those frames. From here, you can either go on to create a bar chart or a line graph.
Bar charts
To create a bar chart, I set up two variants for single bar and stacked bar. Each bar has a coloured fill and a nested resizer. With the frame set to hug, now when the auto layout gap is changed in the resizer, the bar’s size will increase or decrease. For the stacked variant, it’s just a case of adding an additional frame with coloured fill and resizer per section, which you can see below with green and blue sections.
A full bar chart can then be created using a group of these resizable bars. Adding the required amount of bars for the data e.g. 12 bars to represent 12 months.
Line charts
In comparison to bar charts, making an adjustable line chart was a bit trickier. The line needed the ability to adjust the start, middle and end points of the line on the y-axis, while appearing seamless across the x-axis.
To achieve this, I’ve created two lines, one increasing and the other decreasing. It’s possible for this to be straight or curved using variants. By keeping the height and width of the diagonal line the same, it was then possible to create an ease in/ease out curve by dragging the bezier handle to the opposite corner of the box, for both top and bottom points of the line. It’s important to keep the curve the same for both sides, as this helps the final chart line look seamless.
You can create variants for lines with different strokes and end point shapes. In the examples here, I’ve just created solid lines with or without a circle end point, but this could include dotted lines and diamonds etc.
Create a line chart section
Using this line component, it was time to combine with a resizer to control the various points of the line.
I did this by creating a left and right side of the line for a section. Each of these sides have an instance of the line component set to “fill” and a resizer component below. This gives the ability to control the start and end points of the chart section line independently of each other.
Then an overarching resizer which spans the full width of the chart section is used to control the available space at the top.
With the height of this new section component set to “fixed”, any change to the resizer’s gap will increase or decrease the available space for the line to fill.
Combine chart sections
Like with bar charts, several chart sections can be combined to create a chart. The more sections, the more data points in the chart. For the demo in this article I’ve used three sections.
Creating more variations
Using this approach, it’s possible to expand and create single, multi, straight and curved lines variants.
Editing a chart instance
With the chart components now created, I can add an instance into any project using the library and update data points, without detaching. This allows me to represent different scenarios, simply by changing the gap value in auto layout, yet still receiving updates from the library.
The next experiment I’d like to try is using Figma variables or Tokens Studio to control the size of these gaps in the resizer.
What’s going on underneath?
The best way to illustrate the mechanics behind these charts is to switch to the outline view. Here you can see the influence the resizers are having on the charts.
A future with flexible chart components
I’ve really enjoyed exploring and experimenting with this way to create flexible chart components in Figma.
I believe this approach could empower design system teams to maintain data visualizations across their products while allowing designers the flexibility to update data points for their project needs.
Originally posted at medium by Stuart Smith