注意:本地引入使用的话, l-f2的这个包引入要与绘图在同一目录,不然会一直报引入文件路径找不到的错误,暂时没有找到问题的原因。
<template>
<view class="chart-line">
<l-f2 ref="exponentChart"></l-f2>
</view>
</template>
<script>
import F2 from './l-f2/f2.min.js'
import lF2 from './l-f2/l-f2.vue'
export default {
components: {
lF2
},
props:{
},
data() {
return {
data:[{
time: '2017-06-05',
tem: 1000
}, {
time: '2017-06-06',
tem: 2200
}, {
time: '2017-06-07',
tem: 2000
}, {
time: '2017-06-08',
tem: 2600
}, {
time: '2017-06-09',
tem: 2000
}, {
time: '2017-06-11',
tem: 2600
}, {
time: '2017-06-12',
tem: 2800
}]
};
},
mounted() {
this.init()
},
methods: {
init() {
this.$refs.exponentChart.init(config => {
config.appendPadding = [10,22,0,12]
const chart = new F2.Chart(config)
chart.source(this.data);
chart.scale({
time: {
type: 'timeCat',
tickCount: 3,
}
});
chart.axis('time', {
line: {
lineWidth: 1,
stroke: '#ebebeb'
},
label: function label(text, index, total) {
const textCfg = {
fontSize: 12,
lineHeight: 17
};
if (index === 0) {
textCfg.textAlign = 'left';
} else if (index === total - 1) {
textCfg.textAlign = 'right';
}
return textCfg;
},
labelOffset: 6,
});
chart.axis('tem', {
labelOffset: 6,
label: () => {
const cfg = {
fontSize: 12,
lineHeight: 17,
fill: '#999'
}
return cfg;
},
grid: {
stroke: '#eee'
}
});
chart.tooltip({
custom: true,
showXTip: true,
showYTip: true,
snap: true,
crosshairsType: 'xy',
crosshairsStyle: {
lineWidth: 2,
lineDash: [ 2 ]
},
xTipBackground:{
radius: 2,
fill: 'rgba(0, 0, 0, 0.7)',
padding: [6,6]
},
yTipBackground:{
radius: 2,
fill: 'rgba(0, 0, 0, 0.7)',
padding: [6,6]
}
})
chart.area().position('time*tem').color('l(90) 0:#3f7ae8 1:#fefefe').shape('smooth');
chart.line().position('time*tem').color('#3f7ae8').shape('smooth');
chart.render();
return chart
})
}
}
};
</script>
<style lang="scss" scoped>
.chart-line {
height: 400rpx;
}
</style>