### Link to Example Viewer
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Example of using the 'exampleViewPath' built-in variable to link to an example for viewing, with edit and reset parameters.
```markdown
[line-simple](${exampleViewPath}scatter-exponential-regression&edit=1&reset=1)
```
--------------------------------
### Link to Example Editor
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Example of using the 'exampleEditorPath' built-in variable to link to an example in the editor, with edit and reset parameters.
```markdown
[line-simple](${exampleEditorPath}line-simple&edit=1&reset=1)
```
--------------------------------
### Linking to ECharts Examples Editor
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Create links to the ECharts examples editor using a specific URL format that includes the example name and edit/reset parameters.
```markdown
[line-simple](${exampleEditorPath}line-simple&edit=1&reset=1)
```
--------------------------------
### Basic Doughnut Chart Configuration
Source: https://echarts.apache.org/handbook/en/how-to/chart-types/pie/doughnut
Configure a basic doughnut chart by setting the 'type' to 'pie' and defining the 'radius' as an array of two strings representing inner and outer radii. This example demonstrates a standard doughnut chart setup.
```javascript
option = {
title: {
text: 'A Case of Doughnut Chart',
left: 'center',
top: 'center'
},
series: [
{
type: 'pie',
data: [
{
value: 335,
name: 'A'
},
{
value: 234,
name: 'B'
},
{
value: 1548,
name: 'C'
}
],
radius: ['40%', '70%']
}
]
};
```
--------------------------------
### Link to echarts.init API Source
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Example of using the 'apiPath' built-in variable to link to the API documentation for echarts.init.
```markdown
[echarts.init](${apiPath}echarts.init)
```
--------------------------------
### Link to Language-Specific Page
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Example of using the 'lang' built-in variable to create a link to a language-specific page, such as 'Get Started'.
```markdown
[Get Started](${lang}/get-started)
```
--------------------------------
### Link to echarts.init API Documentation
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Example of using the 'mainSitePath' built-in variable to link to the main site's API documentation for echarts.init.
```markdown
[echarts.init](${mainSitePath}api.html#echarts.init)
```
--------------------------------
### Full ECharts Example with Drag and Tooltip
Source: https://echarts.apache.org/handbook/en/how-to/interaction/drag
A complete ECharts initialization and configuration demonstrating drag-and-drop points with custom tooltip behavior and real-time data updates.
```javascript
import echarts from 'echarts';
var symbolSize = 20;
var data = [
[15, 0],
[-50, 10],
[-56.5, 20],
[-46.5, 30],
[-22.1, 40]
];
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption({
tooltip: {
triggerOn: 'none',
formatter: function(params) {
return (
'X: ' +
params.data[0].toFixed(2) +
'
Y: ' +
params.data[1].toFixed(2)
);
}
},
xAxis: { min: -100, max: 80, type: 'value', axisLine: { onZero: false } },
yAxis: { min: -30, max: 60, type: 'value', axisLine: { onZero: false } },
series: [
{ id: 'a', type: 'line', smooth: true, symbolSize: symbolSize, data: data }
]
});
myChart.setOption({
graphic: echarts.util.map(data, function(item, dataIndex) {
return {
type: 'circle',
position: myChart.convertToPixel('grid', item),
shape: { r: symbolSize / 2 },
invisible: true,
draggable: true,
ondrag: echarts.util.curry(onPointDragging, dataIndex),
onmousemove: echarts.util.curry(showTooltip, dataIndex),
onmouseout: echarts.util.curry(hideTooltip, dataIndex),
z: 100
};
})
});
window.addEventListener('resize', function() {
myChart.setOption({
graphic: echarts.util.map(data, function(item, dataIndex) {
return { position: myChart.convertToPixel('grid', item) };
})
});
});
function showTooltip(dataIndex) {
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: dataIndex
});
}
function hideTooltip(dataIndex) {
myChart.dispatchAction({ type: 'hideTip' });
}
function onPointDragging(dataIndex, dx, dy) {
data[dataIndex] = myChart.convertFromPixel('grid', this.position);
myChart.setOption({
series: [
{
id: 'a',
data: data
}
]
});
}
```
--------------------------------
### Install ECharts using npm
Source: https://echarts.apache.org/download.html
Install the Apache ECharts library into your project using the npm package manager. This is a common method for web development projects.
```bash
npm install echarts
```
--------------------------------
### Performance Optimization for High-Dimensional Data
Source: https://echarts.apache.org/handbook/en/basics/release-note/5-2-0
This example demonstrates how to configure a dataset for high-dimensional data visualization. The optimization ensures shared dataset storage, improving memory usage and initialization performance.
```javascript
const indices = Array.from(Array(1000), (_, i) => {
return `index${i}`;
});
const option = {
xAxis: { type: 'category' },
yAxis: {},
dataset: {
// dimension: ['date', . . indices],
source: Array.from(Array(10), (_, i) => {
return {
date: i,
... .indices.reduce((item, next) => {
item[next] = Math.random() * 100;
return item;
}, {})
};
})
},
series: indices.map(index => {
return { type: 'line', name: index };
})
};
```
--------------------------------
### Configure Dataset Mapping with seriesLayoutBy
Source: https://echarts.apache.org/handbook/en/concepts/dataset
Demonstrates how to use `seriesLayoutBy` to map rows or columns of a dataset to chart series. The example shows both 'row' and 'column' layouts for different coordinate systems.
```javascript
option = {
legend: {},
tooltip: {},
dataset: {
source: [
['product', '2012', '2013', '2014', '2015'],
['Matcha Latte', 41.1, 30.4, 65.1, 53.3],
['Milk Tea', 86.5, 92.1, 85.7, 83.1],
['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4]
]
},
xAxis: [
{ type: 'category', gridIndex: 0 },
{ type: 'category', gridIndex: 1 }
],
yAxis: [{ gridIndex: 0 }, { gridIndex: 1 }],
grid: [{ bottom: '55%' }, { top: '55%' }],
series: [
// These series will show in the first coordinate, each series map a row in dataset.
{ type: 'bar', seriesLayoutBy: 'row', xAxisIndex: 0, yAxisIndex: 0 },
{ type: 'bar', seriesLayoutBy: 'row', xAxisIndex: 0, yAxisIndex: 0 },
{ type: 'bar', seriesLayoutBy: 'row', xAxisIndex: 0, yAxisIndex: 0 },
// These series will show in the second coordinate, each series map a column in dataset.
{ type: 'bar', seriesLayoutBy: 'column', xAxisIndex: 1, yAxisIndex: 1 },
{ type: 'bar', seriesLayoutBy: 'column', xAxisIndex: 1, yAxisIndex: 1 },
{ type: 'bar', seriesLayoutBy: 'column', xAxisIndex: 1, yAxisIndex: 1 },
{ type: 'bar', seriesLayoutBy: 'column', xAxisIndex: 1, yAxisIndex: 1 }
]
};
```
--------------------------------
### Rich Text Styling Example
Source: https://echarts.apache.org/handbook/en/how-to/label/rich-text
Demonstrates advanced rich text styling with various text and background properties, including borders, shadows, and custom styles for different text fragments.
```javascript
option = {
series: [
{
type: 'scatter',
symbolSize: 1,
data: [
{
value: [0, 0],
label: {
show: true,
formatter: [
'Plain text',
'{textBorder|textBorderColor + textBorderWidth}',
'{textShadow|textShadowColor + textShadowBlur + textShadowOffsetX + textShadowOffsetY}',
'{bg|backgroundColor + borderRadius + padding}',
'{border|borderColor + borderWidth + borderRadius + padding}',
'{shadow|shadowColor + shadowBlur + shadowOffsetX + shadowOffsetY}'
].join('\n'),
backgroundColor: '#eee',
borderColor: '#333',
borderWidth: 2,
borderRadius: 5,
padding: 10,
color: '#000',
fontSize: 14,
shadowBlur: 3,
shadowColor: '#888',
shadowOffsetX: 0,
shadowOffsetY: 3,
lineHeight: 30,
rich: {
textBorder: {
fontSize: 20,
textBorderColor: '#000',
textBorderWidth: 3,
color: '#fff'
},
textShadow: {
fontSize: 16,
textShadowBlur: 5,
textShadowColor: '#000',
textShadowOffsetX: 3,
textShadowOffsetY: 3,
color: '#fff'
},
bg: {
backgroundColor: '#339911',
color: '#fff',
borderRadius: 15,
padding: 5
},
border: {
color: '#000',
borderColor: '#449911',
borderWidth: 1,
borderRadius: 3,
padding: 5
},
shadow: {
backgroundColor: '#992233',
padding: 5,
color: '#fff',
shadowBlur: 5,
shadowColor: '#336699',
shadowOffsetX: 6,
shadowOffsetY: 6
}
}
}
}
]
}
],
xAxis: {
show: false,
min: -1,
max: 1
},
yAxis: {
show: false,
min: -1,
max: 1
}
};
```
--------------------------------
### Pie Chart Data Transition
Source: https://echarts.apache.org/handbook/en/basics/release-note/5-2-0
Demonstrates data updates in a pie chart with transitions. This example shows how data changes can be animated smoothly within the same series type.
```javascript
function makeRandomData() {
return [
{
value: Math.random(),
name: 'A'
},
{
value: Math.random(),
name: 'B'
},
{
value: Math.random(),
name: 'C'
}
];
}
option = {
series: [
{
type: 'pie',
radius: [0, '50%'],
data: makeRandomData()
}
]
};
setInterval(() => {
myChart.setOption({
series: {
data: makeRandomData()
}
});
}, 2000);
```
--------------------------------
### Link to xAxis.type Source Code
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Example of using the 'optionPath' built-in variable to link to the source code of a specific option property.
```markdown
[xAxis.type](${optionPath}xAxis.type)
```
--------------------------------
### JavaScript Setup for Animating Contour on Globe
Source: https://echarts.apache.org/examples/en/editor.html?c=animating-contour-on-globe&gl=1
Initializes configuration, canvas, and context for rendering. Loads necessary D3.js libraries and an image for contour generation.
```javascript
var config = {
color: '#c0101a',
levels: 1,
intensity: 4,
threshold: 0.01
};
var canvas = document.createElement('canvas');
canvas.width = 4096;
canvas.height = 2048;
context = canvas.getContext('2d');
context.lineWidth = 0.5;
context.strokeStyle = config.color;
context.fillStyle = config.color;
context.shadowColor = config.color;
$.when(
$.getScript(CDN_PATH + 'd3-array@2.8.0/dist/d3-array.js'),
$.getScript(CDN_PATH + 'd3-contour@2.0.0/dist/d3-contour.js'),
$.getScript(CDN_PATH + 'd3-geo@2.0.1/dist/d3-geo.js'),
$.getScript(CDN_PATH + 'd3-timer@2.0.0/dist/d3-timer.js')
).done(function () {
image(ROOT_PATH + '/data-gl/asset/bathymetry_bw_composite_4k.jpg').then(
function (image) {
var m = image.height,
n = image.width,
values = new Array(n * m),
contours = d3.contours().size([n, m]).smooth(true),
projection = d3.geoIdentity().scale(canvas.width / n),
path = d3.geoPath(projection, context);
// StackBlur.R(image, 5);
for (var j = 0, k = 0; j < m; ++j) {
for (var i = 0; i < n; ++i, ++k) {
values[k] = image.data[k << 2] / 255;
}
}
var opt = {
image: canvas
};
var results = [];
function update(threshold, levels) {
context.clearRect(0, 0, canvas.width, canvas.height);
```
--------------------------------
### Code Embedding with Comments
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Example demonstrating a recommended way to write code, avoiding syntactically problematic styles like incomplete comments within code blocks.
```javascript
option = {
series: [
{
type: 'bar'
// ...
}
]
};
```
--------------------------------
### Configure Dataset with External Transform
Source: https://echarts.apache.org/handbook/en/concepts/data-transform
Configure a dataset to use a registered external transform, specifying its type and any necessary parameters. This example shows how to apply an exponential regression using ecStat.
```javascript
option = {
dataset: [
{
source: rawData
},
{
transform: {
// Reference the registered external transform.
// Note that external transform has a namespace (like 'ecStat:xxx'
// has namespace 'ecStat').
// built-in transform (like 'filter', 'sort') does not have a namespace.
type: 'ecStat:regression',
config: {
// Parameters needed by the external transform.
method: 'exponential'
}
}
}
],
xAxis: { type: 'category' },
yAxis: {},
series: [
{
name: 'scatter',
type: 'scatter',
datasetIndex: 0
},
{
name: 'regression',
type: 'line',
symbol: 'none',
datasetIndex: 1
}
]
};
```
--------------------------------
### Basic Pie Chart - ECharts
Source: https://echarts.apache.org/examples/en/editor.html?c=pie-pattern
A fundamental pie chart example. Use this as a starting point for creating simple pie charts with ECharts.
```javascript
option = {
title: {
text: 'Awesome Pie',
subtext: 'Purely based on ECharts',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a}
{b} : {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
data: ['Direct Access', 'Email Marketing', 'Affiliates', 'Video Ads', 'Search Engine']
},
series: [
{
name: 'Access From',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: [
{ value: 335, name: 'Direct Access' },
{ value: 310, name: 'Email Marketing' },
{ value: 234, name: 'Affiliates' },
{ value: 135, name: 'Video Ads' },
{ value: 548, name: 'Search Engine' }
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
```
--------------------------------
### Initialize and Load Scripts
Source: https://echarts.apache.org/examples/en/editor.html?c=globe-contour-paint&gl=1
Sets up configuration, canvas, and context, then asynchronously loads necessary D3.js scripts.
```javascript
var config = {
color: '#c0101a',
levels: 50,
intensity: 100,
threshold: 0.01
};
var canvas = document.createElement('canvas');
canvas.width = 4096;
canvas.height = 2048;
context = canvas.getContext('2d');
context.lineWidth = 0.4;
context.strokeStyle = config.color;
context.fillStyle = config.color;
context.shadowColor = config.color;
$.when(
$.getScript(CDN_PATH + 'd3-array@2.8.0/dist/d3-array.js'),
$.getScript(CDN_PATH + 'd3-contour@2.0.0/dist/d3-contour.js'),
$.getScript(CDN_PATH + 'd3-geo@2.0.1/dist/d3-geo.js'),
$.getScript(CDN_PATH + 'd3-timer@2.0.0/dist/d3-timer.js')
).done(function () {
// Image loading and processing follows
});
```
--------------------------------
### Bar Chart with Axis Breaks Configuration
Source: https://echarts.apache.org/examples/en/editor.html?c=bar-breaks-simple
This JavaScript code configures a bar chart with axis breaks. It defines the data for the breaks, including start and end points and the gap size. This setup is useful for visualizing data where there are large gaps or outliers that would otherwise compress the main data range.
```javascript
var _currentAxisBreaks = [
{
start: 5000,
end: 100000,
gap: '1.5%'
},
{
// `start` and `end` are also used as the identifier for a certain axis break.
start: 105000,
end: 3100000,
gap: '1.5%'
}
];
option = {
title: {
text: 'Bar Chart with Axis Breaks',
subtext: 'Click the break area to expand it',
left: 'center',
textStyle: {
fontSize: 20
},
subtextStyle: {
color: '#175ce5',
fontSize: 15,
fontWeight: 'bold'
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {},
grid: {
top: 120
},
xAxis: [
{
type: 'category',
```
--------------------------------
### Initialize Simplex Noise and Configuration
Source: https://echarts.apache.org/examples/en/editor.html?c=bar3d-noise-modified-from-marpi-demo&gl=1
Loads the Simplex Noise script and initializes a configuration object for the visualization. This includes setting up parameters for waves, colors, and randomization.
```javascript
$.getScript(CDN_PATH + 'simplex-noise@2.4.0/simplex-noise.js').done(
function () {
var simplex = new SimplexNoise();
var UPDATE_DURATION = 1000;
function initVisualizer() {
var config = {
numWaves: 2,
randomize: randomize,
color1: '#000',
color2: '#300',
color3: '#fff',
size: 150,
roughness: 0.5,
metalness: 0
};
//gui.add(config, "numWaves", 1, 3).name("Waves number").onChange(update).listen();
for (var i = 0; i < 2; i++) {
config['wave' + i + 'axis' + 'x'] = Math.random();
config['wave' + i + 'axis' + 'y'] = Math.random();
config['wave' + i + 'rounding'] = Math.random();
config['wave' + i + 'square'] = Math.random();
}
function randomize() {
//config.numWaves = Math.floor(Math.random() * 3) + 1;
for (var i = 0; i < 2; i++) {
config['wave' + i + 'axis' + 'x'] = Math.random();
config['wave' + i + 'axis' + 'y'] = Math.random();
config['wave' + i + 'rounding'] = Math.random();
config['wave' + i + 'square'] = Math.random();
}
// Iterate over all controllers
for (var i in gui.__controllers) {
gui.__controllers[i].updateDisplay();
}
update();
}
function update() {
var item = [];
var dataProvider = [];
var mod = 0.1;
```
--------------------------------
### Embedding ECharts Examples via Iframe
Source: https://echarts.apache.org/handbook/en/meta/edit-guide
Use the 'md-example' component to embed ECharts examples using an iframe. The 'src' attribute corresponds to the example identifier.
```html