Files
SaaS-lib/lib/component/echarts/components/chart/tool.js
xuziqiang d0155dbe3c push
2024-05-15 17:29:42 +08:00

90 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import chartdatas from './chartData.json';
const chartDatas = chartdatas;
export function getAllChartdatas(){
return chartDatas;
}
export function getChartData(name,childName){
return chartDatas[name][childName];
}
export function tranNumber(num){
let numStr = num.toString();
let numV = 0;
// 十万以内直接返回
if (numStr.length < 5 ) {
return numStr;
}else if(numStr.length>=5 && numStr.length<=7){
// 单位用K
numV =parseInt(num/1000);
return numV+'K';
}else if(numStr.length>=8 && numStr.length<=10){
numV =parseInt(num/10000);
return numV+'W';
}else if(numStr.length>=11){
numV =parseInt(num/100000000);
return numV+'M';
}
};
// 折线 图表 统一弹窗
/**
*
*
* @export
* @param {*} name 标题
* backgrouncolor 背景色
* @param {*} data 数据
* @param {*} seriesName 系列名
* @param {*} label 数据后面的单位
*/
export function lineToolTips(name,backgrouncolor,data,seriesName,index){
// var res = `<div>
// </div>`
// var top = index==0?0:15;
var res = `<div style="font-size:12px; color:#ffffff;text-align:left;">
<span style="display:inline-block;margin-right:0px;width:8px;height:8px;border-radius:0px;background-color:${backgrouncolor};"></span>
<span style="margin-right:3px;opacity: 0.65;">${seriesName}</span>
<span style="opacity: 0.65;">${name}</span>
<span style="font-weight:400;color:#fff;margin-left:3px;">
${data}</span>
</div>`
return res;
}
/**
*
*
* @export 16进制颜色值转RGB
* @param {*} color
* @return {*}
*/
export function colorTransferToRgb(color) {
var colorObj = {r:0,g:0,b:0};
if (typeof color !== 'string' && !(color instanceof String)) return console.error("请输入16进制字符串形式的颜色值");
color = color.charAt(0) === '#' ? color.substring(1) : color;
if (color.length !== 6 && color.length !== 3) return console.error("请输入正确的颜色值")
if (color.length === 3) {
color = color.replace(/(\w)(\w)(\w)/, '$1$1$2$2$3$3')
}
var reg = /\w{2}/g;
var colors = color.match(reg);
for (var i = 0; i < colors.length; i++) {
colors[i] = parseInt(colors[i], 16).toString();
if(i==0){
colorObj.r = parseInt(colors[i]);
}else if(i==1){
colorObj.g = parseInt(colors[i]);
}else if(i==2){
colorObj.b = parseInt(colors[i]);
}
}
return colorObj;
}