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);
};
相关推荐
祈澈菇凉2 小时前
Webpack的基本功能有哪些
前端·javascript·vue.js
小纯洁w2 小时前
Webpack 的 require.context 和 Vite 的 import.meta.glob 的详细介绍和使用
前端·webpack·node.js
想睡好3 小时前
css文本属性
前端·css
qianmoQ3 小时前
第三章:组件开发实战 - 第五节 - Tailwind CSS 响应式导航栏实现
前端·css
zhoupenghui1683 小时前
golang时间相关函数总结
服务器·前端·golang·time
White graces3 小时前
正则表达式效验邮箱格式, 手机号格式, 密码长度
前端·spring boot·spring·正则表达式·java-ee·maven·intellij-idea
庸俗今天不摸鱼3 小时前
Canvas进阶-4、边界检测(流光,鼠标拖尾)
开发语言·前端·javascript·计算机外设
bubusa~>_<4 小时前
解决npm install 出现error,比如:ERR_SSL_CIPHER_OPERATION_FAILED
前端·npm·node.js
流烟默4 小时前
vue和微信小程序处理markdown格式数据
前端·vue.js·微信小程序
梨落秋溪、5 小时前
输入框元素覆盖冲突
java·服务器·前端