g2plot 折线图,颜色填充

在这里插入图片描述

 initleftThree(data) {
            const areaPlot = new g2plot_5.Area(document.getElementById('leftThree'), {
                title: {
                    visible: true,
                    text: '',
                },
                smooth: true,
                data,
                xField: 'year',
                yField: 'value',
                color: 'rgba(0,255,119,1)',
                areaStyle: {
                    fill: 'rgba(0,255,119,1)',
                },
                xAxis: {
                    type: 'dateTime',
                    tickCount: 3,
                    label: {
                        style: {
                            fill: '#fff',
                        }
                    },
                },
                yAxis: {
                    label: {
                        style: {
                            fill: '#fff',
                        }
                    },
                }
            });
            areaPlot.render();
        }

initleftThree(data.response[0].annual_production);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!要实现前端g2plot折线图和柱状图结合并且还有缩略轴,您可以按照以下步骤进行操作: 1. 导入所需的库和数据。 ```javascript import { Chart } from '@antv/g2'; import { DataView } from '@antv/data-set'; const data = [ { month: '2021-01', sales: 200, profit: 40 }, { month: '2021-02', sales: 300, profit: 60 }, { month: '2021-03', sales: 400, profit: 80 }, { month: '2021-04', sales: 500, profit: 100 }, { month: '2021-05', sales: 600, profit: 120 }, { month: '2021-06', sales: 700, profit: 140 }, { month: '2021-07', sales: 800, profit: 160 }, { month: '2021-08', sales: 900, profit: 180 }, { month: '2021-09', sales: 1000, profit: 200 }, { month: '2021-10', sales: 1100, profit: 220 }, { month: '2021-11', sales: 1200, profit: 240 }, { month: '2021-12', sales: 1300, profit: 260 }, ]; ``` 2. 数据处理。将数据按照需要的格式进行处理,并将时间格式转换为datetime类型。 ```javascript const ds = new DataView(); ds.source(data) .transform({ type: 'map', callback: (row) => { row.date = new Date(row.month).getTime(); return row; }, }) .transform({ type: 'sort-by', fields: ['date'], }); ``` 3. 绘制折线图和柱状图。 ```javascript const chart = new Chart({ container: 'container', autoFit: true, height: 500, }); chart.data(ds.rows); chart.axis('date', { label: { formatter: (value) => { return new Date(value).toLocaleDateString('en-US', { month: 'short', year: 'numeric', }); }, }, }); chart.line().position('date*sales'); chart .interval() .position('date*profit') .color('#2ecc71'); chart.render(); ``` 4. 绘制缩略轴。 ```javascript const sliderChart = new Chart({ container: 'slider-container', autoFit: true, height: 50, }); sliderChart.data(ds.rows); sliderChart.axis('date', { label: null, tickLine: null, }); sliderChart .interval() .position('date*sales') .color('#2ecc71'); sliderChart.tooltip(false); sliderChart.interaction('element-highlight'); sliderChart.render(); ``` 5. 合并图表。使用Slider将折线图、柱状图和缩略轴合并在一起。 ```javascript const slider = new Slider({ dom: '#slider', width: 'auto', height: 26, padding: [10, 30, 0, 30], start: 0, end: 0.5, xAxis: { type: 'time', tickCount: 10, mask: 'MMM YY', }, yAxis: { type: 'linear', tickCount: 3, }, data: ds.rows, backgroundChart: { type: 'line', options: { xField: 'date', yField: 'sales', smooth: true, lineStyle: { lineWidth: 2, stroke: '#2ecc71', }, }, }, foregroundChart: { type: 'interval', options: { xField: 'date', yField: 'profit', color: '#2ecc71', }, }, }); slider.render(); ``` 这样,您就可以得到一个包含折线图、柱状图和缩略轴的可交互式数据可视化图表了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值