antv g2plot 2.4.7版本堆叠柱线图表并加上slider
时间: 2024-05-17 18:13:02 浏览: 123
您好!要使用AntV G2Plot 2.4.7版本创建堆叠柱线图表并加上slider,可以按照以下步骤进行:
1. 安装G2Plot和Slider组件:
```
npm install @antv/g2plot@2.4.7
npm install @antv/component@2.2.6
```
2. 导入G2Plot和Slider组件:
```javascript
import { StackedColumnLine } from '@antv/g2plot';
import { Slider } from '@antv/component';
```
3. 准备数据:
```javascript
const data = [
{ year: '2010', type: 'Sales', value: 2750 },
{ year: '2010', type: 'Expenses', value: 1150 },
{ year: '2011', type: 'Sales', value: 3500 },
{ year: '2011', type: 'Expenses', value: 1250 },
{ year: '2012', type: 'Sales', value: 4200 },
{ year: '2012', type: 'Expenses', value: 1300 },
{ year: '2013', type: 'Sales', value: 5000 },
{ year: '2013', type: 'Expenses', value: 1600 },
{ year: '2014', type: 'Sales', value: 6500 },
{ year: '2014', type: 'Expenses', value: 1900 },
];
```
4. 创建堆叠柱线图表并添加slider:
```javascript
const plot = new StackedColumnLine('container', {
data,
xField: 'year',
yField: 'value',
stackField: 'type',
line: {},
});
const slider = new Slider({
domContainer: '#slider-container',
width: 500,
height: 26,
padding: [5, 10],
data: data.map((d) => d.year),
xAxis: {
tickCount: 5,
label: null,
title: null,
line: null,
},
yAxis: null,
start: 0,
end: 0.6,
backgroundChart: {
type: 'line',
options: {
data,
xField: 'year',
yField: 'value',
smooth: true,
},
},
});
slider.addEventListener('sliderchange', ({ startValue, endValue }) => {
plot.filter('year', (val) => {
return (
Number(val) >= Number(startValue) && Number(val) <= Number(endValue)
);
});
plot.render();
});
plot.render();
slider.render();
```
这样,您就可以创建一个堆叠柱线图表并加上slider了。具体效果可以参考G2Plot官方文档中的[堆叠柱线图表示例](https://g2plot.antv.vision/zh/examples/column/stacked-column-line#stacked-column-line)。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)