复现的demo
import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'case-report-trend',
autoFit: true,
marginBottom: 0,
marginLeft: 0,
marginRight: 10,
title: '',
});
chart.data([
{ date: '06-10', count: 0, type: '测试' },
{ date: '06-11', count: 0, type: '测试' },
{ date: '06-12', count: 0, type: '测试' },
{ date: '06-13', count: 0, type: '测试' },
{ date: '06-14', count: 0, type: '测试' },
{ date: '06-15', count: 0, type: '测试' },
{ date: '06-16', count: 0, type: '测试' }
]);
chart
.line()
.encode('x', 'date')
.encode('y','count')
.encode('shape', 'smooth')
.encode('color', 'type')
.scale('color', {
domain: ['测试'],
range: ['#FF9410'],
})
.style('lineWidth', 2)
.legend(false)
.scale('y', { independent: true, nice: true })
.axis('x', {
labelFill: '#fff',
tickStroke: '#fff',
lineStroke: '#fff',
labelStroke: '#fff',
labelFontSize: 12,
tick: true,
line: true,
title: '',
})
.axis('y', {
labelFill: '#fff',
tickStroke: '#fff',
lineStroke: '#fff',
labelStroke: '#fff',
gridStroke: '#fff',
labelFontSize: 12,
gridLineWidth: 1,
gridLineDash: [1, 0],
tick: true,
grid: true,
title: '',
labelFormatter: (v: any) =>
v >= 10000 ? (v / 10000).toFixed(0) + '万' : v,
})
.tooltip({ items: [{ channel: 'y', name: '测试' }] });
chart.render();