Apache ECharts From Mermaid

Clone this repo:

Branches

  1. efb5e5f Merge pull request #3 from apache/dependabot/npm_and_yarn/picomatch-2.3.2 by Zhongxiang Wang · 3 days ago main
  2. 74e0276 chore(deps-dev): bump picomatch from 2.3.1 to 2.3.2 by dependabot[bot] · 14 days ago
  3. dcc04e7 Merge pull request #2 from apache/dependabot/npm_and_yarn/flatted-3.4.2 by Zhongxiang Wang · 14 days ago
  4. b819bee chore(deps-dev): bump flatted from 3.3.2 to 3.4.2 by dependabot[bot] · 3 weeks ago
  5. cf2a51f update .asf.yaml by Zhongxiang Wang · 3 months ago

Apache ECharts From Mermaid

A plugin that enables Apache ECharts to render charts using Mermaid-like syntax.

This plugin is particularly useful when you want to generate charts from text/markdown, especially in LLM applications. Instead of having LLMs generate complex ECharts options directly, you can use this plugin to convert simpler Mermaid-like syntax into ECharts options. This approach is more reliable since Mermaid syntax is much simpler than ECharts' option structure.

To customize the chart's appearance, you can use echarts.registerTheme to apply your preferred theme.

Usage

import { EChartsFromMermaid } from 'echarts-from-mermaid';
import * as echarts from 'echarts';

const mermaidDefinition = `
pie title Pets adopted by volunteers
    "Dogs" : 386
    "Cats" : 85
    "Rats" : 15
`;

const option = EChartsFromMermaid.getOption(mermaidDefinition);
/** which generates the following option:
 * {
 *   title: {
 *     text: 'Pets adopted by volunteers'
 *   },
 *   series: [
 *     {
 *       type: 'pie',
 *       data: [
 *         { value: 386, name: 'Dogs' },
 *         { value: 85, name: 'Cats' },
 *         { value: 15, name: 'Rats' }
 *       ]
 *     }
 *   ]
 * }
 */

// This option can be used directly with ECharts.
const chart = echarts.init(document.getElementById('main'));
chart.setOption(option);

Supported Charts

Note that the supported charts are neither a subset nor a superset of the charts supported by Mermaid. This plugin is designed to generate ECharts Options in a syntax that is inspired by Mermaid.

  • Pie (pie)
  • Bar (xychart-beta, or simplified as xychart)
  • Line (xychart-beta, or simplified as xychart)

More chart types will be supported in the future.