@devops-web/cs-chart
Version:
## 更新流程 1. 切换源到npm官方源https://registry.npmjs.org/ 2. npm login 3. npm run lib 4. 修改package.json中的版本号 5. npm publish --access public
76 lines (67 loc) • 1.6 kB
JavaScript
import bar from './plugins/bar.js';
import hbar from './plugins/hbar.js';
import hbar2 from './plugins/hbar2.js';
import line from './plugins/line.js';
import hline from './plugins/hline.js';
import pie from './plugins/pie.js';
import progress from './plugins/progress.js';
import gauge from './plugins/gauge.js';
const chartList = [
line, // 折线图
hbar, // 条形图
hbar2, // 条形图
bar, // 柱状图
hline, // 水平折线图
pie, // 环形图
progress, // 进度环
gauge, // 时速表
];
let COLORS = [
'#0046FF',
'#5ab1ef',
'#fa6e86',
'#ffb980',
'#0067a6',
'#c4b4e4',
'#d87a80',
'#9cbbff',
'#d9d0c7',
'#87a997',
'#d49ea2',
'#5b4947',
'#7ba3a8',
];
export function getColors() {
return COLORS;
}
export function setColors(colors) {
if (!colors || !Array.isArray(colors)) {
console.log('Expect an array colors, the current color is:', colors);
return false;
}
COLORS = colors;
return true;
}
// 获取 支持的图表列表
export function getChartList() {
return [...chartList];
}
// 根据类型获取对应的图表
export function getChart(sType) {
return chartList.find((chart) => chart.type === sType) || chartList[0];
}
// 添加一种类型的图表
export function appendChart(chart) {
const sType = chart.type;
const nIndex = chartList.findIndex((chart) => chart.type === sType);
if (nIndex === -1) {
// append
console.log('register chart:', sType);
chartList.push(chart);
} else {
// update
console.log('update chart:', sType);
chartList[nIndex] = chart;
}
return true;
}