import Chart from 'chart.js/auto';
const ctx = document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: 'Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)', 'rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: { beginAtZero: true }
}
}
});
import * as echarts from 'echarts';
const chartDom = document.getElementById('main');
const myChart = echarts.init(chartDom);
const option = {
title: { text: 'Sales Trend' },
tooltip: { trigger: 'axis' },
legend: { data: ['Sales', 'Profit'] },
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
yAxis: { type: 'value' },
series: [
{ name: 'Sales', type: 'line', stack: 'Total', data: [120, 132, 101, 134, 90, 230, 210] },
{ name: 'Profit', type: 'line', stack: 'Total', data: [820, 932, 901, 934, 1290, 1330, 1320] }
]
};
option && myChart.setOption(option);
import * as d3 from 'd3';
const data = [
{ name: 'A', value: 10 }, { name: 'B', value: 20 }, { name: 'C', value: 15 },
{ name: 'D', value: 25 }, { name: 'E', value: 18 }
];
const width = 400;
const height = 300;
const radius = Math.min(width, height) / 2;
const svg = d3.select('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', `translate(${width / 2},${height / 2})`);
const color = d3.scaleOrdinal()
.domain(data.map(d => d.name))
.range(d3.schemeCategory10);
const pie = d3.pie().sort(null).value(d => d.value);
const arc = d3.arc().innerRadius(0).outerRadius(radius);
const labelArc = d3.arc().innerRadius(radius * 0.7).outerRadius(radius * 0.7);
const arcs = svg.selectAll('.arc')
.data(pie(data))
.enter()
.append('g')
.attr('class', 'arc');
arcs.append('path')
.attr('d', arc)
.attr('fill', d => color(d.data.name));
arcs.append('text')
.attr('transform', d => `translate(${labelArc.centroid(d)})`)
.attr('text-anchor', 'middle')
.text(d => d.data.name);
import React from 'react';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
const data = [
{ name: 'Jan', sales: 1200, profit: 400 },
{ name: 'Feb', sales: 1900, profit: 600 },
{ name: 'Mar', sales: 1500, profit: 500 },
{ name: 'Apr', sales: 2100, profit: 700 },
{ name: 'May', sales: 1800, profit: 600 }
];
function SalesChart() {
return (
<LineChart width={500} height={300} data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="sales" stroke="#8884d8" activeDot={{ r: 8 }} />
<Line type="monotone" dataKey="profit" stroke="#82ca9d" />
</LineChart>
);
}
const option = {
tooltip: {
trigger: 'axis',
axisPointer: { type: 'cross', label: { backgroundColor: '#6a7985' } }
},
toolbox: {
feature: {
dataZoom: { yAxisIndex: 'none' },
saveAsImage: {}
}
},
series: [
{ name: 'Sales', type: 'line', data: [120, 132, 101, 134, 90, 230, 210], markPoint: { data: [{ type: 'max', name: 'Max' }, { type: 'min', name: 'Min' }] }, markLine: { data: [{ type: 'average', name: 'Average' }] } }
]
};
myChart.on('click', function(params) {
console.log(params);
});
window.addEventListener('resize', function() {
myChart.resize();
});