Chart
As explain in the section on working with data and Reports, the <Chart>
component supports report objects and bookmark IDs directly.
But when you create your own Insight or Plugin, you sometimes need to map your own data results to the JSON format that is understood by the <Chart>
component.
Each JSON chart object consists of two sections — the context
and the data
. A minimal chart object for a line chart looks like this:
This is displayed by the chart as:
The data
supplied to <Chart data={...}>
can be either an array of chart object(s), or a single chart object.
When supplying an array with multiple chart objects, it allows the end-user to quickly switch between chart visualizations and data presentations using a dropdown list in the title, but you're then required need to provide a title
in the context
of each chart data object in the array. You can also supply an array with one chart object.
Note that you can mix different chart types each with its own context
and data
— for example one bar chart for funnel conversion steps, then a line chart for conversion over time.
Context object
Line charts
{ "context": { "timeUnit": "total", "timeBy": "Created at date and time", "dateRanges": [ "Average Week" ], "segments": [
},
Bar charts
Overriding data context with props
Most options that can be set in the context
of the data object itself, can also be supplied directly to the <Chart>
component as a prop.
Any properties given to <Chart>
directly override any same ones from the data context. This so you can easily change axis labels, formatting and such, without having to change the data context object.
For example:
This would be the same as if specified in the data context like this:
Upper and lower range bands
When you have a line chart, you can add a lower and upper band. For this to work properly, your data object needs to have exactly three values.
By supplying the data context or chart property ranges
, which is an object indicating which array indexes from values
are the lower, middle and upper bands:
note
Range bands only work for line charts, with exactly one date range, without any group by or segments. The chart data should also have exactly three values — more or less than three values will not work.
Because a custom SQL query with certain column names mapped can be used with a <Chart>
directly, you can use range bands here as well:
Custom chart visualizations
The <Chart>
component currectly only supports line and bar charts. While this is enough in most cases, and we will add support for more chart types in the near future.
Because the <Chart>
component is based on Highcharts, it allows you to construct any custom Highcharts compatible chart supplying a Highcharts options object directly as the raw
property of the chart component:
See the Highcharts examples page for an overview of all different chart visualizations.
Below an example of an Insight that creates a custom scatter plot and sankey diagram:
Here is how the code would look like, where scatter
and sankey
are taken directly from the options object as used in the Highcharts examples: