Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { DualAxes } from '@ant-design/plots';
import React from 'react';
import { createRoot } from 'react-dom';

const DemoDualAxes = () => {
const uvBillData = [
{ time: '2025-03', value: 350, group: 'uv', type: 'a' },
{ time: '2025-04', value: 900, group: 'uv', type: 'a' },
{ time: '2025-05', value: 300, group: 'uv', type: 'a' },
{ time: '2025-06', value: 450, group: 'uv', type: 'a' },
{ time: '2025-07', value: 470, group: 'uv', type: 'a' },

{ time: '2025-03', value: 350, group: 'uv', type: 'b' },
{ time: '2025-04', value: 900, group: 'uv', type: 'b' },
{ time: '2025-05', value: 300, group: 'uv', type: 'b' },
{ time: '2025-06', value: 450, group: 'uv', type: 'b' },
{ time: '2025-07', value: 470, group: 'uv', type: 'b' },
Comment on lines +13 to +17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

uvBillDatagroup: 'uv' 的两组数据(type: 'a'type: 'b')是完全相同的。这会导致堆叠效果不明显,因为两个系列的值一样。为了更好地展示堆叠柱状图的效果,建议修改其中一组数据的值,使其有所区别。

Suggested change
{ time: '2025-03', value: 350, group: 'uv', type: 'b' },
{ time: '2025-04', value: 900, group: 'uv', type: 'b' },
{ time: '2025-05', value: 300, group: 'uv', type: 'b' },
{ time: '2025-06', value: 450, group: 'uv', type: 'b' },
{ time: '2025-07', value: 470, group: 'uv', type: 'b' },
{ time: '2025-03', value: 400, group: 'uv', type: 'b' },
{ time: '2025-04', value: 500, group: 'uv', type: 'b' },
{ time: '2025-05', value: 600, group: 'uv', type: 'b' },
{ time: '2025-06', value: 350, group: 'uv', type: 'b' },
{ time: '2025-07', value: 570, group: 'uv', type: 'b' },


{ time: '2025-03', value: 220, group: 'bill', type: 'c' },
{ time: '2025-04', value: 300, group: 'bill', type: 'c' },
{ time: '2025-05', value: 250, group: 'bill', type: 'c' },
{ time: '2025-06', value: 220, group: 'bill', type: 'c' },
{ time: '2025-07', value: 362, group: 'bill', type: 'c' },
];

const transformData = [
{ time: '2025-03', count: 800 },
{ time: '2025-04', count: 600 },
{ time: '2025-05', count: 400 },
{ time: '2025-06', count: 380 },
{ time: '2025-07', count: 220 },
];

const config = {
xField: 'time',
legend: {
color: {
itemMarker: (datum) => {
if (datum === 'count') {
return 'dash';
} else {
return 'square';
}
},
},
},
children: [
{
data: uvBillData,
type: 'interval',
yField: 'value',
colorField: 'type',
seriesField: 'group',
stack: {
groupBy: ['x', 'series'],
},
group: true,
tooltip: {
items: [
(datum) => {
return {
name: `${datum.group}_${datum.type}`,
value: datum.value,
};
},
],
},
},
{
data: transformData,
type: 'line',
yField: 'count',
style: { lineWidth: 2 },
axis: { y: { position: 'right' } },
},
],
};
return <DualAxes {...config} />;
};

createRoot(document.getElementById('container')).render(<DemoDualAxes />);
8 changes: 8 additions & 0 deletions site/examples/statistics/dual-axes/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@
"en": "Grouped column multi line"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*xzh4RYzYTFcAAAAAAAAAAAAAARQnAQ"
},
{
"filename": "grouped-stacked-column-line.js",
"title": {
"zh": "分组堆叠柱线图表",
"en": "Grouped stacked column line"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*hhUWS6yU84YAAAAAQWAAAAgAemJ7AQ/fmt.avif"
}
]
}