
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@tslsmart/charts
Advanced tools
同时支持vue2
和vue3
项目;支持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
时,则需要是有name
和data
属性的对象数组:
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
时,则需要是有name
和data
属性的对象数组:
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 // 必须是小数
})
FAQs
We found that @tslsmart/charts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.