Mekko chart
Compare two measures across variable-width stacked columns with the Mekko component.
A Mekko chart (also known as a Marimekko or mosaic chart) shows two measures at once as stacked columns: widthMeasure sets each column’s width, and heightMeasure sets the height of the segments stacked inside it. Use it to compare the size and the composition of categories at the same time — for example, market share by width and product mix by height.
Mekko is @beta: it’s mostly stable, but details may still change outside of the usual SemVer guarantees. See API maturity before you depend on it.Buckets
| Prop | Required | Takes | What it does |
|---|---|---|---|
widthMeasure | No | One measure | Sets the width of each column, proportional to its value. With stackBy, a column’s width is the sum of its segments’ widthMeasure values. Without widthMeasure, all columns are equally wide. |
heightMeasure | No | One measure | Sets the height of each column, or of each segment with stackBy, read off the Y axis. |
viewBy | No | One attribute | Draws one column per attribute value. |
stackBy | No | One attribute | Splits each column into segments, one per attribute value. |
filters | No | Filters | Limits the data the Mekko chart shows. |
Sorting
Mekko applies no default sorting. To sort the data, pass sort items in the sortBy prop. With stackBy set, measure sorts don’t go to the execution. The chart applies the first measure sort in sortBy in the browser, provided it sorts by widthMeasure or heightMeasure, and orders the columns by their total value of that measure. Other measure sorts are ignored. Attribute sorts go to the execution.
Configuration
Pass these options in the config prop. See Chart configuration for details.
| Option | What it changes |
|---|---|
colors, colorPalette, colorMapping | Colors of the segments, one per stackBy value. Without stackBy, all columns share one color. |
legend | Whether the legend shows and where. |
dataLabels | visible shows or hides the labels. totalsVisible shows or hides the totals of stacked columns. style: "backplate" adds a background behind the labels. |
stackMeasuresToPercent | With stackBy, stacks the segments of each column to 100%. If any heightMeasure value is negative, the chart falls back to regular stacking. |
xaxis, yaxis | Visibility, labels, rotation, and name of the axes. yaxis.min and yaxis.max set the scale of the height axis. |
grid | enabled shows or hides the grid lines. |
separators | Thousands and decimal separators in the number format. |
zoomInsight | Lets users zoom and pan along the axis with the viewBy values. |
enableCompactSize | Hides axis labels and names when the chart is too small for them. Has no effect when zoomInsight is on. |
Limits
- A column can’t have a negative width. If a column’s
widthMeasurevalue is negative, the chart shows an error andonErrorreceives aNegativeValuesSdkError. WithstackBy, the check uses the sum of the column’s segments. NegativeheightMeasurevalues are allowed. - Columns whose
widthMeasurevalue (withstackBy, the sum of their segments) is zero or empty aren’t drawn. - Without
heightMeasureandstackBy, the chart draws flat columns, labels them with theirwidthMeasurevalues when data labels are on, and hides the Y axis. WithstackBy, it stacks each column’s segments to 100% by theirwidthMeasurevalues instead. - A Mekko chart renders up to 10,000 columns and up to 10,000
stackByvalues. With more, the chart shows an error andonErrorreceives aDataTooLargeToDisplaySdkError. Filter the data to fit. - Mekko charts work best with a moderate number of
viewByandstackByvalues — too many columns or segments make the relative widths and heights hard to compare.
Usage patterns
Width and height measures
widthMeasure controls how wide each column is relative to the others, and heightMeasure controls how tall the stacked segments inside it are. viewBy creates one column per attribute value, and stackBy splits each column into segments:
<Mekko
widthMeasure={Md.$MarketSize}
heightMeasure={Md.$Revenue}
viewBy={Md.Segment}
stackBy={Md.ProductLine}
/>
Structure
import "@gooddata/sdk-ui-charts/styles/css/main.css";
import { Mekko } from "@gooddata/sdk-ui-charts";
<Mekko
widthMeasure={<measure>}
heightMeasure={<measure>}
viewBy={<attribute>}
stackBy={<attribute>}
config={<chart-config>}
…
/>
Example
import "@gooddata/sdk-ui-charts/styles/css/main.css";
import { Mekko } from "@gooddata/sdk-ui-charts";
import * as Md from "./catalog.js";
const style = { height: 300 };
<div style={style}>
<Mekko
widthMeasure={Md.$TotalRevenue}
heightMeasure={Md.$NrOfOrders}
viewBy={Md.Region}
stackBy={Md.Product.Name}
/>
</div>
Props
| Prop | Type | Required | Description | Inherited from |
|---|---|---|---|---|
backend | IAnalyticalBackend | No | Analytical backend, from which the chart will obtain data to visualize If you do not specify instance of analytical backend using this prop, then you MUST have BackendProvider up in the component tree. | IBucketChartProps |
config | IChartConfig | No | Configure chart’s behavior and appearance. | ICommonChartProps |
drillableItems | ExplicitDrill[] | No | Configure drillability; e.g. which parts of the visualization can be interacted with. | IVisualizationProps |
ErrorComponent | ComponentType<IErrorProps> | No | React component to display in the event when there is an error with either obtaining the data from backend or with the data itself. | IVisualizationProps |
execConfig | IExecutionConfig | No | Execution configuration, will provide the execution with necessary config before initiating execution. | ICommonChartProps |
exportTitle | string | No | Set title to use for exported files. | IVisualizationProps |
filters | NullableFiltersOrPlaceholders | No | Specify filters to apply on the data to chart. | IMekkoBucketProps |
height | number | No | Set height of the chart (in pixels). | ICommonChartProps |
heightMeasure | MeasureOrPlaceholder | No | Specify the measure that sets each column’s height, read off the Y axis. | IMekkoBucketProps |
LoadingComponent | ComponentType<ILoadingProps> | No | React component to display while loading data from the backend. | IVisualizationProps |
locale | string | No | Set Locale for visualization localization. | IVisualizationProps |
onDataView | OnDataView | No | (Alpha) Called when the visualization loads a DataView, i.e. it receives data from the backend. | IVisualizationCallbacks |
onDrill | OnFiredDrillEvent | No | Called when user triggers a drill on a visualization. | IVisualizationCallbacks |
onError | OnError | No | Called when an error occurs while loading data for the visualization. | IVisualizationCallbacks |
onExportReady | OnExportReady | No | Called when the visualization is ready to be exported. | IVisualizationCallbacks |
onLegendReady | OnLegendReady | No | Called when legend is rendered. | IChartCallbacks |
onLoadingChanged | OnLoadingChanged | No | Called when loading status of the visualization changes - vis starts or stops loading | IVisualizationCallbacks |
placeholdersResolutionContext | any | No | Resolution context for composed placeholders. | IMekkoBucketProps |
sortBy | SortsOrPlaceholders | No | Specify how to sort the data to chart. | IMekkoBucketProps |
stackBy | AttributeOrPlaceholder | No | Specify the attribute used to stack the columns into segments. | IMekkoBucketProps |
viewBy | AttributeOrPlaceholder | No | Specify the attribute used to create the columns (one column per attribute element). | IMekkoBucketProps |
width | number | No | Set width of the chart (in pixels). | ICommonChartProps |
widthMeasure | MeasureOrPlaceholder | No | Specify the measure that sets each column’s width (proportional to its value). | IMekkoBucketProps |
workspace | string | No | Identifier of analytical workspace, from which the chart will obtain data to visualize. If you do not specify workspace identifier, then you MUST have WorkspaceProvider up in the component tree. | IBucketChartProps |
Related
Display vertical bar comparisons with the ColumnChart component.
Display hierarchical data as nested rectangles with the Treemap component.
Configure chart appearance, axes, legends, colors, and data labels.
Shared behavior of GoodData.UI visual components — responsive sizing, the style and data props model, and the visualization lifecycle callbacks.