Bizchart图表封装之基础折线箱型图(自定义图例、设置Slider)

一、基础折线箱形图的封装

1、概念

           基础折线箱型图=箱型图+折线图,在箱型图的基础上增加折线图,折线图一般用来表示平均数。

2、封装说明

       同之前的基础箱型图,本次封装包括:自定义图例、滚动条Slider

import React from "react";
import {
  Chart,
  Geom,
  Axis,
  Tooltip,
} from "bizcharts";
// @ts-ignore
import Slider from 'bizcharts-plugin-slider';
// @ts-ignore
import DataSet from '@antv/data-set';
import {dealSliderChange, filterSliderData} from "@/pages/charts/utils/chartsCommon";

interface IBasicBoxAndLineProps {
  data: any[]; // 数据源
  xAxis: string; // x轴坐标
  avg: string; // 平均数
  boxValue: string; // 代表值的字段  具体值的样式为 [number,number,number,number,number]
  height?:number;
  maxLen?:number;
  colors?:[string,string]; // 图表的颜色,colors[0]:箱型图颜色;colors[1]:折线图颜色;
}

/**
 * 带平均数箱型图(在箱型图的基础上增加折线图(表示平均数))
 *   自定义tooltip比较麻烦,好在基础箱型图官网有自定义图例demo
 * @param props
 * @constructor
 */
const BasicBoxAndLine:React.FC<IBasicBoxAndLineProps>=(props)=>{
  const {height=400,xAxis,boxValue,data,maxLen,avg,colors=['#1890FF','#fdae6b']}=props;
  let flag:boolean=false;
  let ds:any;
  let dv:any;
  // 是否传入maxLen(有滚动条时必须传入)
  if(maxLen){
    // 设置一个flag,用来判断是否出现滚动条(以及是否需要处理数据)
    flag=data.length>maxLen;
    if(flag){
      const startLength = 0;
      const endLength = maxLen - 1;
      ds=new DataSet({
        state: {
          start: data[startLength][xAxis],
          end: data[endLength][xAxis],
        },
      });
      dv=ds.createView
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值