VChart开箱即用的多端图表库

文章目录

VChart简介

  • VisActor
    • VChart,不只是开箱即用的多端图表库,更是生动灵活的数据故事讲述者。
      • 一码多端
        • 自动适配桌面、H5、多个小程序环境
        • 本仓库包含如下包:
          vchart:核心包,VChart 图表
          react-vchart:基于 React 封装的 VChart 图表组件
          taro-vchart:基于 Taro 封装的 VChart 图表组件
          lark-vchart:基于 飞书小程序 封装的 VChart 图表组件
          tt-vchart: 基于 抖音小程序 封装的 VChart 图表组件
          block-vchart:基于 飞书小组件 封装的 VChart 图表组件
          wx-vchart:基于 微信小程序 封装的 VChart 图表组件
          docs: VChart 站点源码,同时也包含站点所有的中英文文档、图表示例代码等内容。
      • 综合应用标注、动画、流程控制、叙事模板等一系列增强功能进行叙事可视化创作

VChart使用

  • 快速上手
  • 图表示例
    • 图表分类:按名称、按目的、按形状、按组件更多示例
  • 基础的spec-基础配置包括图表类型、数据data和系列配置等等
    • 图表类型 'common' 组合图

      'area' 面积图

      'line' 折线图

      'bar' 柱状图

      'bar3d' 3D 柱状图

      'histogram' 直方图

      'histogram3d' 3D 直方图

      'rangeColumn' 区间柱图

      'rangeColumn3d' 3D 区间柱图

      'rangeArea' 区间面积图

      'map' 地图

      'pie' 饼图

      'pie3d' 3D 饼图

      'radar' 雷达图

      'rose' 玫瑰图

      'scatter' 散点图

      'sequence' 时序图

      'circularProgress' 环形进度条

      'linearProgress' 条形进度条

      'wordCloud' 词云

      'wordCloud3d' 3D 词云

      'funnel' 漏斗图

      'funnel3d' 3D 漏斗图

      'waterfall' 瀑布图

      'boxPlot' 箱型图

      'gauge' 仪表盘

      'sankey' 桑基图

      'treemap' 矩形树图

      'sunburst' 旭日图

      'circlePacking' circlePacking

      'heatmap' 热力图

    • 组件配置 'axes' 坐标轴

      'legends' 图例

      'tooltip' 提示框

      'crosshair' crosshair(鼠标hover上的十字准星线,一般只有一条竖虚线)

      'brush' 框选交互组件

      'scrollbar' 滚动条

      'dataZoom' 数据筛选滑块

      'player' 播放器

      'markLine' 标记线

      'markArea' 标记区域

      'markPoint' 标记点

      'indicator' 指标卡

      'title' 标题

  • 详细配置文档

React VChart使用

折线图示例
  • 折线图通过将一系列数据点进行连接,构造出趋势。
  • 折线图用于分析事物随时间或有序类别而变化的趋势。如果有多组数据,则用于分析多组数据随时间变化或有序类别的相互作用和影响。
js 复制代码
const spec = {
  type: 'line',
  data: {
    values: [
      { type: 'Nail polish', country: 'Africa', value: 4229 },
      { type: 'Nail polish', country: 'EU', value: 4376 },
      { type: 'Nail polish', country: 'China', value: 3054 },
      { type: 'Nail polish', country: 'USA', value: 12814 },
      { type: 'Eyebrow pencil', country: 'Africa', value: 3932 },
      { type: 'Eyebrow pencil', country: 'EU', value: 3987 },
      { type: 'Eyebrow pencil', country: 'China', value: 5067 },
      { type: 'Eyebrow pencil', country: 'USA', value: 13012 },
      { type: 'Rouge', country: 'Africa', value: 5221 },
      { type: 'Rouge', country: 'EU', value: 3574 },
      { type: 'Rouge', country: 'China', value: 7004 },
      { type: 'Rouge', country: 'USA', value: 11624 },
      { type: 'Lipstick', country: 'Africa', value: 9256 },
      { type: 'Lipstick', country: 'EU', value: 4376 },
      { type: 'Lipstick', country: 'China', value: 9054 },
      { type: 'Lipstick', country: 'USA', value: 8814 },
      { type: 'Eyeshadows', country: 'Africa', value: 3308 },
      { type: 'Eyeshadows', country: 'EU', value: 4572 },
      { type: 'Eyeshadows', country: 'China', value: 12043 },
      { type: 'Eyeshadows', country: 'USA', value: 12998 },
      { type: 'Eyeliner', country: 'Africa', value: 5432 },
      { type: 'Eyeliner', country: 'EU', value: 3417 },
      { type: 'Eyeliner', country: 'China', value: 15067 },
      { type: 'Eyeliner', country: 'USA', value: 12321 },
      { type: 'Foundation', country: 'Africa', value: 13701 },
      { type: 'Foundation', country: 'EU', value: 5231 },
      { type: 'Foundation', country: 'China', value: 10119 },
      { type: 'Foundation', country: 'USA', value: 10342 },
      { type: 'Lip gloss', country: 'Africa', value: 4008 },
      { type: 'Lip gloss', country: 'EU', value: 4572 },
      { type: 'Lip gloss', country: 'China', value: 12043 },
      { type: 'Lip gloss', country: 'USA', value: 22998 },
      { type: 'Mascara', country: 'Africa', value: 18712 },
      { type: 'Mascara', country: 'EU', value: 6134 },
      { type: 'Mascara', country: 'China', value: 10419 },
      { type: 'Mascara', country: 'USA', value: 11261 }
    ]
  },
  title: {
    visible: true,
    text: 'Stacked line chart'
  },
  stack: true,
  xField: 'type',
  yField: 'value',
  seriesField: 'country',
  line: {
    style: {
      curveType: 'monotone'
    }
  },
  point: {
    style: {
      size: 0,
      fill: 'white',
      stroke: null,
      lineWidth: 2
    },
    state: {
      dimension_hover: {
        size: 10
      }
    }
  },
  axes:[
    {
      orient: 'left',
      label: {
        // 纵坐标轴数字千分位展示
        formatter: '{label:,}',
      }
    }
  ],
  // 十字准星线
  crosshair: {
    xField: {
      visible: true,
      line: {
        type: 'line',
        style: {
          stroke: '#5266CC',
          // 竖直准星线为实线
          lineDash: [0],
        },
      },
    },
  },
  // 缩略轴
  dataZoom: [
    {
      orient: "bottom",
      start: 0,
      // 默认滑块位置100%
      end: 1,
    },
  ],
  // 滚动条
  scrollBar: [
    {
      orient: 'bottom',
      start: 0,
      end: 0.5,
      roam: true
    }
  ],
  // 图例
  legends: [
    {
      visible: true,
      // 横向当前行列的对齐方式
      position: "middle",
      // 纵向图例位置
      orient: "top",
    },
  ],
};

const root = document.getElementById(CONTAINER_ID);
const { VChart } = ReactVChart;
const { useState, useRef, useEffect } = React;

const Card = () => {
  const chartRef = useRef(null);
  useEffect(() => {
    window['vchart'] = chartRef;
  }, []);

  const handleSelectDimension = () => {
    if (chartRef.current) {
      chartRef.current.setDimensionIndex('Rouge', {
        showTooltipOption: {
          y: 100
        }
      });
    }
  };

  return (
    <div>
      <VChart ref={chartRef} spec={spec} />
      <button
        style={{ position: 'absolute', top: 0, left: '50%', transform: 'translate(-50%, 0)' }}
        onClick={handleSelectDimension}
      >
        Select 'Rouge'
      </button>
    </div>
  );
};

ReactDom.createRoot(root).render(<Card />);

// release react instance, do not copy
window.customRelease = () => {
  ReactDom.unmountComponentAtNode(root);
};
相关推荐
小鱼儿亮亮几秒前
二、React基础精讲:编写TodoList、事件绑定、JSX语法、组件之间传值
前端·react.js
Mintopia3 分钟前
实时 AIGC:Web 端低延迟生成的技术难点与突破
前端·javascript·aigc
小鱼儿亮亮3 分钟前
五、Redux进阶:UI组件、容器组件、无状态组件、异步请求、Redux中间件:Redux-thunk、redux-saga,React-redux
前端·react.js
Mintopia4 分钟前
Next.js 性能优化双绝:Image 与 next/font 的底层修炼手册
前端·javascript·next.js
jingling5559 分钟前
uniapp | 解决组件样式不生效问题
前端·css·uni-app·html·学习方法
小菜全10 分钟前
使用UniApp实现下拉框和表格组件页面
开发语言·前端·javascript·elementui·前端框架·html
三十_A15 分钟前
【工具】41K star!网页一键变桌面应用
前端·开源
wordbaby38 分钟前
解锁时光机:用 React Hooks 轻松实现 Undo/Redo 功能
前端·react.js
呐谁吃饭了1 小时前
网络安全学习-6
前端
北辰alk1 小时前
深入剖析Redux中间件实现原理:从概念到源码
前端