Index.js File
The Index.js file is the main entry file of a component. This file provides an example for your reference and describes the life cycles and related functions of the common components in the index.js file.
Function |
Description |
---|---|
refresh() |
Default rendering function, which is called when a component is initialized and redrawn. (Custom function implementation) |
resize() |
Scaling function, which is called when a component is dragged or zoomed. |
loadData() |
Data loading function, which is called when a component loads data. (Custom function implementation) |
dispatch(String: eventType, object: data) |
This function is optional. It is used to trigger event interaction. If a component supports interaction, this function can be called by you to configure events in the gui.json file.
|
getRelation() |
Mapping acquisition function, which is called when you obtain the data mapping from the data panel. |
The following is a Index.js file example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
import gui from './gui.json';
import './index.less';
//global: echarts jQuery
class App extends BaseChart {
constructor(props = {}) {
super(props);
Object.assign(props);
this.chart = echarts.init(this.el);
}
refresh() {
this.loadData();
}
loadData() {
let option = this.getOption();
if (option) {
this.chart.setOption(option, true);
}
}
resize() {
this.chart.resize();
}
getOption() {
let styledata = this.config.styledata,
relation = this.getRelation();
let yData = [], data = [];
this.data.forEach(item => {
yData.push(item[relation.x]);
data.push(item[relation.y]);
});
return {
backgroundColor: '222',
grid: {
top: '20',
left: '20',
right: '20',
bottom: '20',
containLabel: true
},
yAxis: [{
type: 'category',
data: yData,
inverse: true,
axisTick: {
show: false
},
axisLabel: {
margin: 10,
textStyle: {
fontFamily: styledata['font'],
fontSize: 24,
color: '#fff'
}
},
axisLine: {
show: false
}
}],
xAxis: [{
type: 'value',
axisLabel: {
show: false
},
axisLine: {
show: false
},
splitLine: {
show: false
}
}],
series: [{
type: 'bar',
barWidth: 14,
data,
label: {
normal: {
show: true,
position: 'insideBottomRight',
formatter: '{c}%',
distance: 0,
offset: [30, -20],
color: '#fff',
fontSize: 16,
padding: [5, 15, 10, 15]
}
},
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
offset: 0,
color: '#57eabf'
}, {
offset: 1,
color: '#2563f9'
}], false),
barBorderRadius: 14
}
}
}, {
type: "bar",
barWidth: 14,
xAxisIndex: 0,
barGap: "-100%",
data: [120, 120],
itemStyle: {
normal: {
color: "#444a58",
barBorderRadius: 14
}
},
zlevel: -1
}]
};
}
}
App.gui = gui;export default App;
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot