如何使用 v-chart 实现自定义效果
最编程
2024-04-10 21:30:28
...
前言: 我们都知道v-chart 是用e-chart来包装的。使用v-chart,有方便的一面,简化了处理数据的过程。但是,有时候,我们还是需要e-chart那要的配置来实现图标的样式风格自定义的。该如何实现?
v-chart 的官方文档最近这段时间有问题,放一个能用的链接:http://woolen.gitee.io/v-charts/#/line
答案是: 用v-chart 的 extend
属性来弄。内部就看e-cahrt的文档。
示例:
<template>
<ve-histogram
height="240px"
:data="chartData"
:colors="chartColors"
:settings="chartSettings"
:extend="chartExtend"
></ve-histogram>
</template>
export default {
data() {
this.chartExtend = {
legend: {
bottom: 10
// itemHeight: 4,
// itemWidth: 8,
// borderCap: 'round'
},
grid: {
show: true,
top: 35,
bottom: 40,
// left: 10,
// right: 10,
borderColor: '#fff'
// backgroundColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
// { offset: 0, color: '#F6FAFD' },
// { offset: 1, color: '#ffffff' }
// ])
},
xAxis: {
axisLine: {
show: true,
lineStyle: {
color: '#e8e8e8'
}
},
axisLabel: {
rotate: 35,
textStyle: {
color: '#D1D5DB',
fontSize: 10
}
}
},
yAxis: {
nameTextStyle: {
color: '#D1D5DB'
},
axisLabel: {
textStyle: {
color: '#D1D5DB',
fontSize: 12
}
},
axisTick: {
show: true
},
splitNumber: 3,
axisLine: {
show: true,
lineStyle: { color: '#B6B9C0' }
},
// x轴对应的竖线
splitLine: {
show: false,
lineStyle: {
color: ['#E2E4E8'],
// width: 1,
type: 'dash'
}
}
},
tooltip: {
trigger: 'axis',
confine: true
},
// 每个柱子
series(v) {
v.forEach(i => {
// console.log('series', i)
if (i.type == 'bar') {
i.barWidth = 14
i.smooth = true
i.itemStyle = {
barBorderRadius: [2, 2, 0, 0],
// color: '#006EFF',
borderWidth: 0
}
}
})
return v
}
}
return {
chartData:[]
}
}
}
通过extend属性,我们在这个对象内部,就可以针对e-cahrt的一些属性api进行自定义了,内部的参数,查阅e-cahrt官方文档,他们是一致的。
对于其他的饼图、折线图等,都是一样的用法。
2、如何自定义图标的渐变背景颜色?
this.chartExtend = {
legend: {
bottom: 10
},
grid: {
show: true,
top: 35,
bottom: 40,
backgroundColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#F6FAFD' },
{ offset: 1, color: '#ffffff' }
])
},
使用new echarts.graphic.LinearGradient
来实现渐变
3、如何自定义tooltips?
this.pieChartExtend = {
color: [
'#7EC4EC',
'#FA945C',
'#B96EFF',
'#F9E092',
'#4DDEBC',
'#00A6FF',
'#BFEF43',
'#5C58F0',
'#a9E092',
'red',
'blue',
'purple',
'gold'
],
grid: {
containLabel: true
},
tooltip: {
trigger: 'item',
formatter: function (params) {
let index = params.dataIndex
let data = self.pieChartData.rows[index]
let res = `<p><span style='background-color:${
params.color
};width:10px;height:10px;border-radius:50%;display:inline-block;'></span> ${data.name || '--'}:</p>
<p>人数:${data.value}个 </p>
<p>占比: ${params.percent}%</p>
`
return res
},
textStyle: {
fontSize: 14
},
confine: true
},
legend: {
show: true,
bottom: '10'
// align: 'left',
// orient: 'vertical', //垂直显示
// y: 'center', //延Y轴居中
// right: 10,
// itemHeight: 4,
// itemWidth: 8,
// formatter: name => {
// let data = this.pieChartData.rows
// let tarValue = 0
// for (let i = 0; i < data.length; i++) {
// if (data[i].name == name) {
// tarValue = data[i].value
// }
// }
// return name + ' ' + tarValue + '个'
// }
},
// series: {
// center: ['50%', '40%'],
// radius: ['30%', '48%']
// }
series(v) {
v.forEach((item, index) => {
let oriData = item.data[0]
index = index + 1
item.center = ['50%', '40%']
item.radius = ['30%', '48%']
item.hoverAnimation = false
item.label = {
formatter: function (data) {
let name = data.name
if (name.substr(6) && name.length > 6) {
return name.substr(0, 6) + '...\n' + data.value
} else {
return name + '(' + data.value+')'
}
}
}
})
return v
}
}
推荐阅读
-
如何使用 Python 对图像应用扭曲效果
-
如何在自定义过滤器中优雅地实现静态资源释放
-
问:如何配置 NGINX 以提供使用 gzip 压缩的自定义扩展名的文件?
-
使用 JWT、Interceptor 和 ThreadLocal 在任何位置获取令牌中的信息,并将其与自定义注解相结合,实现方法的身份验证。
-
正负偏差变量 即 d2+、d2- 分别表示决策值中超出和未达到目标值的部分。而 di+、di- 均大于 0 刚性约束和目标约束(柔性目标约束有偏差) 在多目标规划中,>=/<= 在刚性约束中保持不变。当需要将约束条件转换为柔性约束条件时,需要将 >=/<= 更改为 =(因为已经有 d2+、d2- 用来表示正负偏差),并附加上 (+dii-di+) 注意这里是 +di、-di+!之所以是 +di,-di+,是因为需要将目标还原为最接近的原始刚性约束条件 优先级因素和权重因素 对多个目标进行优先排序和优先排序 目标规划的目标函数 是所有偏差变量的加权和。值得注意的是,这个加权和都取最小值。而 di+ 和 dii- 并不一定要出现在每个不同的需求层次中。具体分析需要具体问题具体分析 下面是一个例子: 题目中说设备 B 既要求充分利用,又要求尽可能不加班,那么列出的时间计量表达式即为:min z = P3 (d3- + d3 +) 使用 + 而不是 -d3 + 的原因是:正负偏差不可能同时存在,必须有 di+di=0 (因为判定值不可能同时大于目标值和小于目标值),而前面是 min,所以只要取 + 并让 di+ 和 dii- 都为正值即可。因此,得出以下规则: 最后,给出示例和相应的解法: 问题:某企业生产 A 和 B 两种产品,需要使用 A、B、C 三种设备。下表显示了与工时和设备使用限制有关的产品利润率。问该企业应如何组织生产以实现下列目标? (1) 力争利润目标不低于 1 500 美元; (2) 考虑到市场需求,A、B 两种产品的生产比例应尽量保持在 1:2; (3)设备 A 是贵重设备,严禁超时使用; (4)设备 C 可以适当加班,但要控制;设备 B 要求充分利用,但尽量不加班。 从重要性来看,设备 B 的重要性是设备 C 的三倍。 建立相应的目标规划模型并求解。 解:设企业生产 A、B 两种产品的件数分别为 x1、x2,并建立相应的目标计划模型: 以下为顺序求解法,利用 LINGO 求解: 1 级目标: 模型。 设置。 variable/1..2/:x;! s_con_num/1...4/:g,dplus,dminus;!所需软约束数量(g=dplus=dminus 数量)及相关参数; s_con(s_con_num);! s_con(s_con_num,variable):c;!软约束系数; 结束集 数据。 g=1500 0 16 15. c=200 300 2 -1 4 0 0 5; 结束数据 min=dminus(1);!第一个目标函数;!对应于 min=z 的第一小部分;! 2*x(1)+2*x(2)<12;!硬约束 @for(s_con_num(i):@sum(variable(j):c(i,j)*x(j))+dminus(i)-dplus(i)=g(i)); !使用设置完成的数据构建软约束表达式; ! !软约束表达式 @for(variable:@gin(x)); !将变量约束为整数; ! 结束 此时,第一级目标的最优值为 0,第一级偏差为 0: 第二级目标: !求 dminus(1)=0,然后求解第二级目标。 模型。 设置。 变量/1..2/:x;!设置:变量/1..2/:x; ! s_con_num/1...4/:g,dplus,dminus;!软约束数量及相关参数; s_con(s_con_num(s_con_num));! s_con(s_con_num,variable):c;! 软约束系数; s_con(s_con_num,variable):c;! 结束集 数据。 g=1500 0 16 15; c=200 300 2 -1 4 0 0 5; 结束数据 min=dminus(2)+dplus(2);!第二个目标函数 2*x(1)+2*x(2)<12;!硬约束 @for(s_con_num(i):@sum(variable(j):c(i,j)*x(j))+dminus(i)-dplus(i)=g(i)); ! 软约束表达式;! dminus(1)=0; !第一个目标结果 @for(variable:@gin(x)); ! 结束 此时,第二个目标的最优值为 0,偏差为 0: 第三目标 !求 dminus(2)=0,然后求解第三个目标。 模型。 设置。 变量/1..2/:x;!设置:变量/1..2/:x; ! s_con_num/1...4/:g,dplus,dminus;!软约束数量及相关参数; s_con(s_con_num(s_con_num));! s_con(s_con_num,variable):c;! 软约束系数; s_con(s_con_num,variable):c;! 结束集 数据。 g=1500 0 16 15; c=200 300 2 -1 4 0 0 5; 结束数据 min=3*dminus(3)+3*dplus(3)+dminus(4);!第三个目标函数。 2*x(1)+2*x(2)<12;!硬约束 @for(s_con_num(i):@sum(variable(j):c(i,j)*x(j))+dminus(i)-dplus(i)=g(i)); ! 软约束表达式;! dminus(1)=0; !第一个目标约束条件; ! dminus(2)+dplus(2)=0; !第二个目标约束条件 @for(variable:@gin(x));! 结束 最终结果为 x1=2,x2=4,dplus(1)=100,最优利润为
-
第十五讲--如何编写公式实现TDX指标的自定义K线(从零开始编写TDX指标公式系列)
-
Pytorch 实用教程:nn.Linear 在内部是如何实现的,在哪里可以看到源代码?-使用 nn.Linear 的示例代码
-
如何使用网页绘制黑莓 9900 键盘效果图
-
如何使用和自定义 Windows 11 快速设置菜单
-
畅谈如何使用 CSS 滤镜实现凹面平滑圆角效果