v-charts areaStyle All In One
v-charts areaStyle All In One
shit 封装
堆叠面积图
https://codepen.io/xgqfrms/pen/MWEdROy?editors=1010
shit demo
<section class="content">
<ve-line
ref="chart"
class="trend-chart"
style="margin: 20px; width: calc(100% - 40px);"
:data="chartData"
:settings="chartSettings"
:extend="chartExtend"
:colors="chartColors"
:loading="chartLoading"
:data-empty="dataEmpty"
height="300px"
width="auto"
/>
</section>
data () {
return {
chartData: [],
dataEmpty: false,
chartColors: Util.chartColors,
chartLoading: false,
chartSettings: {
type: 'line',
// labelMap: data.labels,
// yAxisType: ['percent'],
},
chartExtend: {
...UtilTableChart.chartExtend('line'),
stack: {
cols: [],
},
area: true,
// grid: {
// bottom: 0,
// },
legend: {
show: true,
},
tooltip: {
formatter: (params) => {
// 多个 column 返回 数组
console.log('params =', params);
let result = '';
for(const [i, param] of params.entries()) {
const {
name,
marker,
value,
} = param;
console.log('param', param, i);
if (i === 0) {
result += `
<span style="color: #0f0;">🚀${name}</span>
<br/>
${marker}${value[1]}<br/>
`;
} else {
result += `${marker}${value[1]}<br/>`;
}
}
return result;
// return 'bug ???';
},
},
series: (v) => {
Array.from(v).forEach((e, idx) => {
e.areaStyle = 'value';
});
return v;
},
},
};
},
async getData () {
this.chartLoading = true;
this.dataEmpty = false;
const params = this.getParams();
if(this.filterData.isDefaultTime) {
params.starttime = dayjs(this.filterData.defaultEndTime).subtract(12, 'months').startOf('months').format('YYYY-MM-DD');
params.endtime = dayjs(this.filterData.defaultEndTime).subtract(1, 'months').endOf('months').format('YYYY-MM-DD');
}
const res = await APIService.getChart(params).finally(() => {
this.chartLoading = false;
});
const {data, labels, xAxisKey: key} = res.data.data;
// console.log('data, labels', data, labels);
// console.log('key', key);
const columns = labels.map(obj => obj.key);
// key: "其他"
// title: "其他"
const rows = this.formatRows(data, columns);
this.chartExtend.stack.cols = columns;
console.log('rows', rows);
this.chartData = {
columns: [key, ...columns],
rows: this.formatRows(data, columns),
// columns: ['日期', '访问用户', '下单用户', '下单率'],
// rows: [
// { '日期': '1/1', '访问用户': 1393, '下单用户': 1093, '下单率': 0.32 },
// { '日期': '1/2', '访问用户': 3530, '下单用户': 3230, '下单率': 0.26 },
// { '日期': '1/3', '访问用户': 2923, '下单用户': 2623, '下单率': 1.76 },
// { '日期': '1/4', '访问用户': 1723, '下单用户': 2423, '下单率': 0.49 },
// { '日期': '1/5', '访问用户': 3792, '下单用户': 3492, '下单率': 0.323 },
// { '日期': '1/6', '访问用户': 4593, '下单用户': 4293, '下单率': 0.78 }
// ],
};
// const id = this.$refs.chart.echarts.id;
// const div = document.querySelector(`[_echarts_instance_="${id}"]`);
// if(div) {
// div.style.display = 'block';
// }
// if (!data.length) {
// if(div) {
// div.style.display = 'none';
// }
// this.dataEmpty = true;
// return;
// }
},
API
refs
https://v-charts.xgqfrms.xyz/#/line?id=settings-配置项
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15840069.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2021-01-24 css background transparent All In One
2021-01-24 vue template All In One
2021-01-24 css position sticky All In One
2020-01-24 sketch 导出 svg
2019-01-24 toast components
2019-01-24 html template & iframe & CORS All In One
2019-01-24 how to know iframe is loaded in js