What Are Custom Charts
Custom charts in OpenObserve let you create visualizations by using SQL to query the data and JavaScript to define how the chart appears. Custom charts are useful when other built-in chart types do not meet your needs.
How to Access Custom Charts
- Go to Dashboards from the left-hand navigation menu.
-
Do one of the following:
- To add the chart to a new dashboard: Click Create Dashboard, enter a dashboard name, description, select folder, and click Save.
- To use an existing dashboard: Select the dashboard from the list. You can optionally add a new tab to organize your panels.
-
Click Add Panel.
- Enter a name for the panel.
- In the Add Panel page, select Custom Chart from the list of charts.
After selecting Custom Chart, the screen displays:
- A SQL editor
- A JavaScript editor
- A chart preview panel
Use these options to write your query, define how the chart should be displayed, and preview the output.
What Data Do We Have
OpenObserve stores ingested data in a flat structure.
Use the Logs page to view the ingested data for a selected time range.
What Data Does the Chart Expect
Using custom charts, you can create and configure any chart supported by ECharts.
Each chart type expects data in a specific structure and format.
Depending on the chart, you may need to prepare the data to ensure the correct data types, and reshape it to match the structure the chart requires.
How to Check the Data Structure a Chart Expects
To identify the data structure expected by a chart:
- Go to https://echarts.apache.org/en/option.html#series.
- Find your chart’s series type.
Example:series-line
,series-bar
,series-sunburst
,series-tree
,series-graph
, etc. - Click the chart type.
-
Navigate to the
data
field under that series type and observe the following:- Flat Data: If it is a flat array of values or objects (data: [1, 2, 3] or [{name, value}]).
- Nested Data: If it has children: [...] inside data items.
Prepare and Reshape Data
After you identify whether the chart expects flat or nested data, you can determine how to prepare and reshape your data.
- Preparation is done using SQL. It includes filtering, aggregating, and converting values (e.g., durations to seconds). The output gets stored into the data object.
- Reshaping is done using JavaScript. It is needed only when the chart expects nested structure (e.g., parent–child). Use JavaScript to convert flat records in the
data
object into the nested data format required by the chart. For charts that expect flat data, no reshaping is needed.
The data
Object
OpenObserve stores the query result in a global object called ` data`
. This is always an array of an array:
data[0]
contains the result set of your query which is an array of rows.- Each item in
data[0]
is an object representing a single row.
The option
Object
In the JavaScript editor, you must construct an object named option
.
This option
object defines how the chart looks and behaves.
Use your query results (data[0]
) to populate fields in the option
object. All chart settings, such as axes
, series
, titles
, tooltips
, etc., must be defined in this option
object.
Components of the option
Object
Here are the main components of the option
object:
1. title
: Sets the chart’s title.
2. tooltip
: Enables hover-over tooltips.
3. legend
: Displays the list of series (or categories) in the chart.
4.xAxis
and yAxis
: Configure the axes for charts like bar or line.
- Use
type: 'category'
for named groups like days or statuses. - Use
type: 'time'
for timestamps. - Use
type: 'value'
for numeric values. - Some charts (like pie or sunburst) do not use axes. In those cases, omit these fields.
5. series
: Defines what data to plot and what type of chart to use.
- Use
type: 'line'
for line charts. - Use
type: 'bar'
for bar charts. - Use
type: 'pie'
,'treemap'
, or'sunburst'
for hierarchical charts. - You can add multiple series to show multiple lines or bars in one chart. Use your query result (data[0]) to build each series. For example:
How Does Custom Charts Work
Creating a custom chart involves the following steps:
- Check what structure and data types the chart expects.
- Select the stream to query.
- Write a SQL query to prepare the data.
- Reshape the result using JavaScript if needed.
- Define the chart using the option object.
- Apply changes to preview the chart.