加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
charts.vue 14.28 KB
一键复制 编辑 原始数据 按行查看 历史
凯文童鞋丶 提交于 2021-03-25 11:37 . 首次提交,开源啦~
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
<template>
<view>
<u-notice-bar mode="horizontal" type="primary" :list="list"></u-notice-bar>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">仪表盘</text>
<text class="text-ABC text-blue">GaugeCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasGauge" id="canvasGauge" class="charts"></canvas>
</view>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">折线图</text>
<text class="text-ABC text-blue">LineCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasArea" id="canvasArea" class="charts" @touchstart="touchArea"></canvas>
</view>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">圆环图</text>
<text class="text-ABC text-blue">ringCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasRing" id="canvasRing" class="charts" @touchstart="touchRing"></canvas>
</view>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">饼状图</text>
<text class="text-ABC text-blue">PieCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasPie" id="canvasPie" class="charts" @touchstart="touchPie"></canvas>
</view>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">柱状图</text>
<text class="text-ABC text-blue">ColumnCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasColumn" id="canvasColumn" class="charts" @touchstart="touchColumn"></canvas>
</view>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">雷达图</text>
<text class="text-ABC text-blue">RadarCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasRadar" id="canvasRadar" class="charts"></canvas>
</view>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">漏斗图</text>
<text class="text-ABC text-blue">FunnelCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasFunnel" id="canvasFunnel" class="charts"></canvas>
</view>
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">词云图</text>
<text class="text-ABC text-blue">DataCharts</text>
</view>
</view>
<view class="chartsMain">
<canvas canvas-id="canvasData" id="canvasData" class="charts"></canvas>
</view>
</view>
</template>
<script>
// 图表
import uCharts from "@/components/u-charts/u-charts.js";
var _self;
var canvaRing = null;
var canvaArea = null;
var canvaGauge = null;
var canvaPie = null;
var canvaColumn = null;
var canvaFunnel = null;
var canvaWord = null;
export default {
data() {
return {
list:[
'图表目前均使用:《uCharts高性能跨端图表》,小程序如需接入Echarts等其他图表,敬请期待作者更新...'
],
cWidth: '',
cHeight: '',
pixelRatio: 1,
// 词云图
"cyData": {
"series": [{
"name": "Vue.js",
"textSize": 28
}, {
"name": "JavaScript",
"textSize": 30
}, {
"name": "微信小程序",
"textSize": 20
}, {
"name": "支付宝小程序",
"textSize": 20
}, {
"name": "头条小程序",
"textSize": 20
}, {
"name": "抖音小程序",
"textSize": 25
}, {
"name": "App开发",
"textSize": 30
}]
},
// 漏斗图
"Funnel": {
"series": [{
"name": "一班",
"data": 50
}, {
"name": "二班",
"data": 30
}, {
"name": "三班",
"data": 20
}, {
"name": "四班",
"data": 18
}, {
"name": "五班",
"data": 8
}]
},
// 柱状图
"Column": {
"categories": ["2012", "2013", "2014", "2015", "2016", "2017"],
"series": [{
"name": "前端学习量",
"data": [15, {
"value": 20,
"color": "#f04864"
}, 45, 37, 43, 34]
}, {
"name": "后台学习量",
"data": [30, {
"value": 40,
"color": "#facc14"
}, 25, 14, 34, 18]
}]
},
// 仪表盘
gaugeWidth: 15,
chartData: {
categories: [{
value: 0.2,
color: '#2fc25b'
}, {
value: 0.8,
color: '#f04864'
}, {
value: 1,
color: '#1890ff'
}],
series: [{
name: '完成率',
data: 0.85
}]
},
// 圆环图
"Ring": {
"series": [{
"name": "一班",
"data": 50
}, {
"name": "二班",
"data": 30
}, {
"name": "三班",
"data": 20
}, {
"name": "四班",
"data": 18
}, {
"name": "五班",
"data": 8
}]
},
// 饼状图
"Pie": {
"series": [{
"name": "一班",
"data": 50
}, {
"name": "二班",
"data": 30
}, {
"name": "三班",
"data": 20
}, {
"name": "四班",
"data": 18
}, {
"name": "五班",
"data": 8
}]
},
// 雷达图
radar: {
categories: ['html/css', 'JavaScript', 'Vue.js', 'react.js', 'angular.js', 'jQuery'],
series: [{
name: '熟悉度',
data: [95, 88, 80, 60, 40, 95]
}]
},
// 折线图
Area: {
categories: ['6月', '7月', '8月', '9月', '10月', '11月', '12月'],
series: [{
name: '学习前端',
data: [100, 80, 95, 150, 112, 132, 151],
color: '#facc14'
}, {
name: '学习后台',
data: [70, 40, 65, 100, 44, 68, 78],
color: '#2fc25b'
}, {
name: '学习设计',
data: [35, 20, 25, 37, 4, 20, 39],
color: '#1890ff'
}]
}
};
},
onLoad() {
_self = this;
this.cWidth = uni.upx2px(750);
this.cHeight = uni.upx2px(420);
this.getServerData();
},
computed: {
},
mounted() {
},
methods: {
getServerData() {
_self.showArea("canvasArea", this.chartData);
_self.showRadar("canvasRadar", this.chartData);
_self.showRing("canvasRing", this.Ring);
_self.showGauge("canvasGauge", this.Gauge);
_self.showPie("canvasPie", this.Pie);
_self.showColumn("canvasColumn", this.Column);
_self.showFunnel("canvasFunnel", this.Column);
_self.showData("canvasData", this.Data);
},
// 词云图
showData(canvasId, chartData) {
canvaWord = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'word',
background: '#ffffff',
pixelRatio: _self.pixelRatio,
series: _self.cyData.series,
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
extra: {
word: {
type: 'normal'
}
}
});
},
// 漏斗图
showFunnel(canvasId, chartData) {
canvaFunnel = new uCharts({
$this: this,
canvasId: canvasId,
type: 'funnel',
fontSize: 11,
// padding: [15, 15, 0, 15],
legend: {
show: true,
padding: 5,
lineHeight: 11,
margin: 0,
},
background: '#FFFFFF',
pixelRatio: this.pixelRatio,
series: this.Funnel.series,
animation: true,
width: this.cWidth * this.pixelRatio,
height: this.cHeight * this.pixelRatio,
dataLabel: true,
extra: {
funnel: {
border: true,
borderWidth: 2,
borderColor: '#FFFFFF'
}
},
})
},
// 柱状图
showColumn(canvasId, chartData) {
canvaColumn = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'column',
legend: true,
fontSize: 11,
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
animation: true,
categories: _self.Column.categories,
series: _self.Column.series,
xAxis: {
disableGrid: true,
},
yAxis: {
//disabled:true
},
dataLabel: true,
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
extra: {
column: {
type: 'group',
width: _self.cWidth * _self.pixelRatio * 0.45 / _self.Column.categories.length
}
}
});
},
touchColumn(e) {
canvaColumn.showToolTip(e, {
format: function(item, category) {
if (typeof item.data === 'object') {
return category + ' ' + item.name + ':' + item.data.value
} else {
return category + ' ' + item.name + ':' + item.data
}
}
});
},
// 仪表盘
showGauge(canvasId, chartData) {
canvaGauge = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'gauge',
fontSize: 11,
legend: false,
title: {
name: Math.round(_self.chartData.series[0].data * 100) + '%',
color: _self.chartData.categories[1].color,
fontSize: 25 * _self.pixelRatio,
offsetY: 50 * _self.pixelRatio, //新增参数,自定义调整Y轴文案距离
},
subtitle: {
name: _self.chartData.series[0].name,
color: '#666666',
fontSize: 15 * _self.pixelRatio,
offsetY: -50 * _self.pixelRatio, //新增参数,自定义调整Y轴文案距离
},
extra: {
gauge: {
type: 'default',
width: _self.gaugeWidth * _self.pixelRatio, //仪表盘背景的宽度
startAngle: 0.75,
endAngle: 0.25,
startNumber: 0,
endNumber: 100,
splitLine: {
fixRadius: 0,
splitNumber: 10,
width: _self.gaugeWidth * _self.pixelRatio, //仪表盘背景的宽度
color: '#FFFFFF',
childNumber: 5,
childWidth: _self.gaugeWidth * 0.4 * _self.pixelRatio, //仪表盘背景的宽度
},
pointer: {
width: _self.gaugeWidth * 0.8 * _self.pixelRatio, //指针宽度
color: 'auto'
}
}
},
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
categories: _self.chartData.categories,
series: _self.chartData.series,
animation: true,
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
dataLabel: true,
});
},
// 圆环图
showRing(canvasId, chartData) {
canvaRing = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'ring',
fontSize: 11,
legend: true,
extra: {
pie: {
offsetAngle: -45,
ringWidth: 30 * _self.pixelRatio,
lableWidth: 15
}
},
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
series: _self.Ring.series,
animation: true,
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
disablePieStroke: true,
dataLabel: true,
});
},
touchRing(e) {
canvaRing.showToolTip(e, {
format: function(item) {
return item.name + ':' + item.data
}
});
},
// 饼状图
showPie(canvasId, chartData) {
canvaPie = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'pie',
fontSize: 11,
legend: true,
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
series: _self.Pie.series,
animation: true,
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
dataLabel: true,
extra: {
pie: {
lableWidth: 15
}
},
});
},
touchPie(e) {
canvaPie.showToolTip(e, {
format: function(item) {
return item.name + ':' + item.data
}
});
},
// 折线图
showArea(canvasId, chartData) {
canvaArea = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'area',
fontSize: 11,
legend: true,
dataLabel: false,
dataPointShape: true,
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
categories: _self.Area.categories,
series: _self.Area.series,
animation: true,
xAxis: {
type: 'grid',
gridColor: '#CCCCCC',
gridType: 'dash',
dashLength: 8
},
yAxis: {
gridType: 'dash',
gridColor: '#CCCCCC',
dashLength: 8,
splitNumber: 5,
min: 10,
max: 180,
},
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
extra: {
area: {
type: 'straight',
opacity: 0.2,
addLine: true,
width: 2
}
}
});
},
touchArea(e) {
canvaArea.showToolTip(e, {
format: function(item, category) {
return item.name + ' ' + category + ' ' + ':' + item.data
}
});
},
// 雷达图
showRadar(canvasId, chartData) {
var canvaRadar = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'radar',
fontSize: 11,
padding: [40, 15, 30, 15],
legend: {
show: false
},
colors: ['#14bcff'],
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
animation: true,
dataLabel: true,
categories: _self.radar.categories,
series: _self.radar.series,
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
extra: {
radar: {
max: 100, //雷达数值的最大值
opacity: 0.6,
labelColor: '#333333'
}
}
});
},
// ucharts end
}
};
</script>
<style lang="scss" scoped>
.chartsMain {
width: 750rpx;
height: 450rpx;
padding-top: 15rpx;
background: #fff;
margin-bottom: 24rpx;
border-top: 2rpx solid #f2f2f2;
.charts {
width: 750rpx;
height: 450rpx;
box-sizing: border-box;
}
}
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化