npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tslsmart/charts

v0.4.1

Published

特斯联通用图表组件库

Downloads

19

Readme

特斯联统一图表组件库

同时支持vue2vue3项目;支持typescript

如果你的 vue 版本低于2.7,则还需要单独安装@vue/composition-api插件:

pnpm i @vue/composition-api

安装

需要配合echarts使用

使用 npm/pnpm:

npm/pnpm i @tslsmart/charts echarts

使用 yarn:

yarn add @tslsmart/charts echarts

水波图

如果要使用水波图,还需要单独安装水波图插件echarts-liquidfill:

pnpm i echarts-liquidfill

使用

图表组件库分为图表组件图表配置两个部分

点击查看详细文档

图表组件

组件接受一个config图表配置对象,对外暴露一个refresh方法,在数据更新了后,可以调用该方法刷新图表

<template>
  <tsl-chart :config="barConfig" ref="chartRef" />
</template>

<script setup>
import { TslChart, defineBaseBar } from '@tslsmart/charts'

const chartRef = ref()

const barConfig = ref({})

// 模拟异步请求数据
setTimeout(() => {
  barConfig.value = defineBaseBar({
    data: [4, 6, 10],
    xAxisData: ['1月', '2月', '3月']
  })

  // 将新的配置应用到图表上面
  chartRef.value.refresh()
}, 1500)
</script>

图表配置

所有的配置函数都是以defineXXX开头的,例如上面的defineBaseBar

配置函数接受一个对象为参数,这个参数中除了特定的属性外,还可以传入echarts本身的配置,函数内部会将开发者的配置与默认配置合并,例如:

import { defineBaseBar } from '@tslsmart/charts'

const config = defineBaseBar({
  data: [4, 6, 10],
  xAxisData: ['1月', '2月', '3月'],
  title: {
    // echarts的配置
    text: '这是一个标题'
  }
})

则最终渲染的时候,标题会是这是一个标题

后面的文档只会讲解特有的参数属性,echarts 的其他配置请移步

基础柱状图

import { defineBaseBar } from '@tslsmart/charts'

const config = defineBaseBar({
  data: [4, 6, 10], // 数据,必填,类型见下文
  xAxisData: ['1月', '2月', '3月'], // x轴数据,必填,字符串数组
  isGroup: true, // 是否合并为一组,非必填,布尔值
  isArea: true, // 是否区域渐变,非必填,布尔值
  direction: 'vertical' // 方向,横版还是竖版,非必填,只能是'horizontal' 或者 'vertical',默认'vertical'
})

其中,当isGroup为 false 时,data 的类型需要是[4, 6, 10]这样的数字数组; 为true时,则需要是有namedata属性的对象数组:

const data = [
  {
    name: '张三',
    data: [4, 10, 2]
  },
  {
    name: '李四',
    data: [6, 4, 6]
  },
  {
    name: '王麻子',
    data: [10, 30, 8]
  }
]

斑马纹柱状图

import { defineZebraBar } from '@tslsmart/charts'

const config = defineZebraBar({
  data: [4, 6, 10], // 数据,必填,类型见下文
  xAxisData: ['1月', '2月', '3月'], // x轴数据,必填,字符串数组
  isGroup: true, // 是否合并为一组,非必填,布尔值
  direction: 'vertical' // 方向,横版还是竖版,非必填,只能是'horizontal' 或者 'vertical',默认'vertical'
})

其中,当isGroup为 false 时,data 的类型需要是[4, 6, 10]这样的数字数组; 为true时,则需要是有namedata属性的对象数组:

const data = [
  {
    name: '张三',
    data: [4, 10, 2]
  },
  {
    name: '李四',
    data: [6, 4, 6]
  },
  {
    name: '王麻子',
    data: [10, 30, 8]
  }
]

堆叠柱状图

import { defineStackBar } from '@tslsmart/charts'

const config = defineStackBar({
  data: [
    {
      name: '张三',
      data: [4, 10, 2, 4, 10, 2, 4, 10, 2]
    },
    {
      name: '李四',
      data: [6, 4, 6, 6, 4, 6, 6, 4, 6]
    },
    {
      name: '王麻子',
      data: [10, 30, 8, 10, 30, 8, 10, 30, 8]
    }
  ], // 必填,必须要有`name`和`data`属性
  xAxisData: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月'], // x轴数据,必填,字符串数组
  direction: 'vertical' // 方向,横版还是竖版,非必填,只能是'horizontal' 或者 'vertical',默认'vertical'
})

基础线图

import { defineBaseLine } from '@tslsmart/charts'
const config = defineBaseLine({
  data: {
      name: '华为',
      data: [4, 6, 10]
    },
    {
      name: '苹果',
      data: [6, 18, 5]
    }, // 数据,需要是对象数组,其中`name`非必填,`data`是必填的,需要是数字数组
  xAxisData: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月'], // x轴数据,必填,字符串数组
  smooth: false, // 是否平滑曲线,非必填,true为平滑曲线,false为折线图
  isArea: true, // 是否区域图,非必填,布尔值
})

玉玦图(环形柱状图)

import { defineCircleBar } from '@tslsmart/charts'

const config = defineCircleBar({
  data: [
    {
      name: '张三', // 必填
      value: 4 // 必填
    },
    {
      name: '李四',
      value: 6
    },
    {
      name: '王麻子',
      value: 10
    }
  ]
})

饼图

import { definePie } from '@tslsmart/charts'

const config = definePie({
  data: [
    { value: 335, name: '直接访问' },
    { value: 310, name: '邮件营销' },
    { value: 234, name: '联盟广告' },
    { value: 135, name: '视频广告' },
    { value: 1548, name: '搜索引擎' }
  ]
})

环形图

import { defineBaseRing } from '@tslsmart/charts'

const config = defineBaseRing({
  data: [
    { value: 335, name: '直接访问' },
    { value: 310, name: '邮件营销' },
    { value: 234, name: '联盟广告' },
    { value: 135, name: '视频广告' },
    { value: 1548, name: '搜索引擎' }
  ],
  borderColor: '#333' // 边框颜色,非必填
})

玫瑰图

import { defineRose } from '@tslsmart/charts'

const config = defineRose({
  data: [
    { value: 3351, name: '直接访问' },
    { value: 3101, name: '邮件营销' },
    { value: 2341, name: '联盟广告' },
    { value: 1351, name: '视频广告' },
    { value: 1541, name: '搜索引擎' }
  ]
})

水波图(水球图)

水波图需要单独安装插件echarts-liquidfill,且配置函数的导入方式也有所变化

安装插件

pnpm i echarts-liquidfill

导入使用

import { defineBaseLiquid } from '@tslsmart/charts/dist/liquid'

const config = defineBaseLiquid({
  data: 0.35 // 必须是小数
})