首页 >> js开发 >> jsVUE+elementui组件在table-cell单元格中绘制微型echarts图js大全
jsVUE+elementui组件在table-cell单元格中绘制微型echarts图js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
需求效果图示例
实际完成效果图
**代码实现注:table表格为二次封装的子组件
-在table表格中 根据 scope.$index动态设置元素的id ,便于指定单元格的echarts初始化;-在单元格中触发一个方法,传入当前的scope.row数据或者指定其他数据,并且传入 scope.$index 以及一个字符串便于识别当前是哪条数据的charts-在方法中绘制echarts**
{{ realRowName(scope.row, '0') || '-' }}
/
{{ isNaN(realRowName(scope.row, '0')) ? '-' : (realRowName(scope.row, '0') / (parseInt(dateType) - calcShelfTime(scope.row.real_created_time, '0') < 0 ? parseInt(dateType): calcShelfTime(scope.row.real_created_time, '0'))).toFixed(0)}}
{{ drawEcharts(scope.row, scope.$index, 'sale') }}
{{ realRowName(scope.row, '0') || '-' }}
/
{{ isNaN(realRowName(scope.row, '0')) ? '-' : (realRowName(scope.row, '0') / (parseInt(dateType) - calcShelfTime(scope.row.real_created_time, '0') < 0 ? parseInt(dateType): calcShelfTime(scope.row.real_created_time, '0'))).toFixed(0)}}
{{ drawEcharts(scope.row, scope.$index, 'sale') }}
绘制echarts的方法(数据仅为示例,实际开发根据传进来的scope.row数据)注意此处初始化echarts对象时采用VUE的this.$nextTick方法,以防获取不到未渲染的节点元素。
drawEcharts() {
//绘制趋势echarts
// console.log(arguments)
let option = {
tooltip: {
trigger: 'axis'
},
// legend: {
//
data: ['每日30天销量分析']
// },
grid: {
left: '10px',
right: '30px',
top: '40px',
bottom: '10px',
containLabel: true
},
xAxis: {
show: false,
type: 'category',
boundaryGap: false,
data: ['03-21', '03-22', '03-23', '03-24', '03-25', '03-26', '03-27']
},
yAxis: {
show: false,
type: 'value'
},
series: [
{
name: '每日30天销量分析',
type: 'line',
data: [120, 500, 101, 86, 173, 230, 6]
}
]
};
let chartId = 'tiger-' + arguments[2] + '-trend-index' + arguments[1];
this.$nextTick(() => {
let myChart = this.echarts.init(document.getElementById(chartId), 'macarons');
myChart.setOption(option);
myChart.resize();
});
},
drawEcharts() {
//绘制趋势echarts
// console.log(arguments)
let option = {
tooltip: {
trigger: 'axis'
},
// legend: {
//
data: ['每日30天销量分析']
// },
grid: {
left: '10px',
right: '30px',
top: '40px',
bottom: '10px',
containLabel: true
},
xAxis: {
show: false,
type: 'category',
boundaryGap: false,
data: ['03-21', '03-22', '03-23', '03-24', '03-25', '03-26', '03-27']
},
yAxis: {
show: false,
type: 'value'
},
series: [
{
name: '每日30天销量分析',
type: 'line',
data: [120, 500, 101, 86, 173, 230, 6]
}
]
};
let chartId = 'tiger-' + arguments[2] + '-trend-index' + arguments[1];
this.$nextTick(() => {
let myChart = this.echarts.init(document.getElementById(chartId), 'macarons');
myChart.setOption(option);
myChart.resize();
});
},AND 不要忘记设置echarts的高度,否则一辈子也出不来图形(示例,根据实施开发调整)
&-frame {
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
.price-bar {
color: red !important;
}
.tiger-trend-charts {
height: 60px;
min-width: 100px;
}
}
&-frame {
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
.price-bar {
color: red !important;
}
.tiger-trend-charts {
height: 60px;
min-width: 100px;
}
}
实际完成效果图
**代码实现注:table表格为二次封装的子组件
-在table表格中 根据 scope.$index动态设置元素的id ,便于指定单元格的echarts初始化;-在单元格中触发一个方法,传入当前的scope.row数据或者指定其他数据,并且传入 scope.$index 以及一个字符串便于识别当前是哪条数据的charts-在方法中绘制echarts**
近{{ dateType }}天累计
/ 日均销量
昨日累计销量
近{{ dateType }}天累计
/ 日均收藏量
昨日累计收藏
{{ realRowName(scope.row, '0') || '-' }}
/
{{ isNaN(realRowName(scope.row, '0')) ? '-' : (realRowName(scope.row, '0') / (parseInt(dateType) - calcShelfTime(scope.row.real_created_time, '0') < 0 ? parseInt(dateType): calcShelfTime(scope.row.real_created_time, '0'))).toFixed(0)}}
{{ drawEcharts(scope.row, scope.$index, 'sale') }}
近{{ dateType }}天累计
/ 日均销量
昨日累计销量
近{{ dateType }}天累计
/ 日均收藏量
昨日累计收藏
{{ realRowName(scope.row, '0') || '-' }}
/
{{ isNaN(realRowName(scope.row, '0')) ? '-' : (realRowName(scope.row, '0') / (parseInt(dateType) - calcShelfTime(scope.row.real_created_time, '0') < 0 ? parseInt(dateType): calcShelfTime(scope.row.real_created_time, '0'))).toFixed(0)}}
{{ drawEcharts(scope.row, scope.$index, 'sale') }}
drawEcharts() {
//绘制趋势echarts
// console.log(arguments)
let option = {
tooltip: {
trigger: 'axis'
},
// legend: {
//
data: ['每日30天销量分析']
// },
grid: {
left: '10px',
right: '30px',
top: '40px',
bottom: '10px',
containLabel: true
},
xAxis: {
show: false,
type: 'category',
boundaryGap: false,
data: ['03-21', '03-22', '03-23', '03-24', '03-25', '03-26', '03-27']
},
yAxis: {
show: false,
type: 'value'
},
series: [
{
name: '每日30天销量分析',
type: 'line',
data: [120, 500, 101, 86, 173, 230, 6]
}
]
};
let chartId = 'tiger-' + arguments[2] + '-trend-index' + arguments[1];
this.$nextTick(() => {
let myChart = this.echarts.init(document.getElementById(chartId), 'macarons');
myChart.setOption(option);
myChart.resize();
});
},
drawEcharts() {
//绘制趋势echarts
// console.log(arguments)
let option = {
tooltip: {
trigger: 'axis'
},
// legend: {
//
data: ['每日30天销量分析']
// },
grid: {
left: '10px',
right: '30px',
top: '40px',
bottom: '10px',
containLabel: true
},
xAxis: {
show: false,
type: 'category',
boundaryGap: false,
data: ['03-21', '03-22', '03-23', '03-24', '03-25', '03-26', '03-27']
},
yAxis: {
show: false,
type: 'value'
},
series: [
{
name: '每日30天销量分析',
type: 'line',
data: [120, 500, 101, 86, 173, 230, 6]
}
]
};
let chartId = 'tiger-' + arguments[2] + '-trend-index' + arguments[1];
this.$nextTick(() => {
let myChart = this.echarts.init(document.getElementById(chartId), 'macarons');
myChart.setOption(option);
myChart.resize();
});
},AND 不要忘记设置echarts的高度,否则一辈子也出不来图形(示例,根据实施开发调整)
&-frame {
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
.price-bar {
color: red !important;
}
.tiger-trend-charts {
height: 60px;
min-width: 100px;
}
}
&-frame {
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
.price-bar {
color: red !important;
}
.tiger-trend-charts {
height: 60px;
min-width: 100px;
}
}