Розробка інтерактивних графіків на ECharts для веб-сайтів
Apache ECharts — потужна бібліотека для складних візуалізацій: тепло вої карти, графи зв'язків, treemaps, sunbursts, scatter plots, графіки свічок. Підходить для дашбордів з великими наборами даних.
Встановлення
npm install echarts echarts-for-react
Базова інтеграція з React
import ReactECharts from 'echarts-for-react';
function RevenueChart({ data }) {
const option = {
tooltip: {
trigger: 'axis',
formatter: (params) => {
const p = params[0];
return `${p.axisValue}<br/>${p.marker}Дохід: <b>${formatCurrency(p.value)}</b>`;
}
},
legend: { data: ['Дохід', 'Прогноз'] },
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
xAxis: {
type: 'category',
boundaryGap: false,
data: data.map(d => d.date)
},
yAxis: {
type: 'value',
axisLabel: { formatter: v => `${(v/1000).toFixed(0)}k` }
},
series: [
{
name: 'Дохід',
type: 'line',
smooth: true,
areaStyle: { opacity: 0.2 },
data: data.map(d => d.revenue),
lineStyle: { color: '#3b82f6' }
},
{
name: 'Прогноз',
type: 'line',
smooth: true,
lineStyle: { type: 'dashed', color: '#f59e0b' },
data: data.map(d => d.forecast)
}
]
};
return (
<ReactECharts
option={option}
style={{ height: 350 }}
opts={{ renderer: 'svg' }}
/>
);
}
Heatmap (Тепло вої карта активності)
function ActivityHeatmap({ data }) {
const option = {
tooltip: { position: 'top' },
grid: { height: '50%', top: '10%' },
xAxis: {
type: 'category',
data: ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'],
splitArea: { show: true }
},
yAxis: {
type: 'category',
data: Array.from({ length: 24 }, (_, i) => `${i}:00`),
splitArea: { show: true }
},
visualMap: {
min: 0, max: 100,
calculable: true,
orient: 'horizontal',
left: 'center',
bottom: '15%',
inRange: { color: ['#f0f9ff', '#0369a1'] }
},
series: [{
name: 'Активність',
type: 'heatmap',
data: data,
label: { show: false },
emphasis: { itemStyle: { shadowBlur: 10 } }
}]
};
return <ReactECharts option={option} style={{ height: 400 }} />;
}
Candlestick (Біржовий графік)
function CandlestickChart({ ohlcData }) {
const option = {
xAxis: {
type: 'category',
data: ohlcData.map(d => d.date)
},
yAxis: { scale: true },
series: [{
type: 'candlestick',
data: ohlcData.map(d => [d.open, d.close, d.low, d.high]),
itemStyle: {
color: '#22c55e',
color0: '#ef4444',
borderColor: '#22c55e',
borderColor0: '#ef4444'
}
}]
};
return <ReactECharts option={option} style={{ height: 400 }} />;
}
DataZoom — Масштабування
const option = {
dataZoom: [
{
type: 'inside',
start: 0,
end: 100
},
{
type: 'slider',
start: 0,
end: 100
}
],
// ... rest of option
};
Динамічне оновлення даних
const chartRef = useRef();
function updateChart(newData) {
const chart = chartRef.current?.getEchartsInstance();
if (!chart) return;
chart.setOption({
series: [{ data: newData }]
}, { notMerge: false });
}
Часові межи
5–7 типів графіків з DataZoom та підказками — 3–5 днів.







