fix: 去掉参数设置,曲线增加点击事件。
This commit is contained in:
@@ -45,6 +45,9 @@
|
||||
type="2d"
|
||||
id="data-query-chart"
|
||||
:style="canvasStyle"
|
||||
@touchend="touchEnd"
|
||||
@touchstart="touchStart"
|
||||
@touchmove="touchMove"
|
||||
></canvas>
|
||||
<view v-if="!loading && (!chartData || chartData.length === 0)" class="empty-data">
|
||||
<text>暂无数据</text>
|
||||
@@ -186,6 +189,8 @@ onUnmounted(() => {
|
||||
const chartWidth = ref(0);
|
||||
const chartHeight = ref(0);
|
||||
const chartPixelRatio = ref(1);
|
||||
const chartTop = ref(0);
|
||||
const chartLeft = ref(0);
|
||||
|
||||
// 初始化图表
|
||||
function initChart() {
|
||||
@@ -438,9 +443,43 @@ function drawChart() {
|
||||
tofix: 2,
|
||||
},
|
||||
extra: {
|
||||
tooltip: {
|
||||
showBox: true,
|
||||
showArrow: true,
|
||||
showCategory: true,
|
||||
borderWidth: 0,
|
||||
borderRadius: 0,
|
||||
borderColor: '#000000',
|
||||
borderOpacity: 0.7,
|
||||
bgColor: '#000000',
|
||||
bgOpacity: 0.7,
|
||||
gridType: 'solid',
|
||||
dashLength: 4,
|
||||
gridColor: '#CCCCCC',
|
||||
boxPadding: 3,
|
||||
fontSize: 13,
|
||||
lineHeight: 20,
|
||||
fontColor: '#FFFFFF',
|
||||
legendShow: true,
|
||||
legendShape: 'auto',
|
||||
splitLine: true,
|
||||
labelBgColor: '#FFFFFF',
|
||||
labelBgOpacity: 0.7,
|
||||
labelFontColor: '#666666',
|
||||
},
|
||||
line: { type: 'curve', width: 2, activeType: 'hollow' },
|
||||
},
|
||||
});
|
||||
|
||||
// 获取 canvas 位置
|
||||
const query = Taro.createSelectorQuery();
|
||||
query.select('#data-query-chart').boundingClientRect();
|
||||
query.exec((res) => {
|
||||
if (res.length > 0 && res[0]) {
|
||||
chartTop.value = res[0].top || 0;
|
||||
chartLeft.value = res[0].left || 0;
|
||||
}
|
||||
});
|
||||
}, 300);
|
||||
} else {
|
||||
// 小程序环境
|
||||
@@ -491,13 +530,88 @@ function drawChart() {
|
||||
tofix: 2,
|
||||
},
|
||||
extra: {
|
||||
tooltip: {
|
||||
showBox: true,
|
||||
showArrow: true,
|
||||
showCategory: true,
|
||||
borderWidth: 0,
|
||||
borderRadius: 0,
|
||||
borderColor: '#000000',
|
||||
borderOpacity: 0.7,
|
||||
bgColor: '#000000',
|
||||
bgOpacity: 0.7,
|
||||
gridType: 'solid',
|
||||
dashLength: 4,
|
||||
gridColor: '#CCCCCC',
|
||||
boxPadding: 3,
|
||||
fontSize: 13,
|
||||
lineHeight: 20,
|
||||
fontColor: '#FFFFFF',
|
||||
legendShow: true,
|
||||
legendShape: 'auto',
|
||||
splitLine: true,
|
||||
labelBgColor: '#FFFFFF',
|
||||
labelBgOpacity: 0.7,
|
||||
labelFontColor: '#666666',
|
||||
},
|
||||
line: { type: 'curve', width: 2, activeType: 'hollow' },
|
||||
},
|
||||
});
|
||||
|
||||
// 获取 canvas 位置
|
||||
const query = Taro.createSelectorQuery();
|
||||
query.select('#data-query-chart').boundingClientRect();
|
||||
query.exec((res) => {
|
||||
if (res.length > 0 && res[0]) {
|
||||
chartTop.value = res[0].top || 0;
|
||||
chartLeft.value = res[0].left || 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 触摸结束事件 - 显示提示框
|
||||
function touchEnd(e: any) {
|
||||
if (!chartInstance) return;
|
||||
|
||||
const x = e.mpEvent.changedTouches[0].clientX;
|
||||
const y = e.mpEvent.changedTouches[0].clientY;
|
||||
const tmpe = { x: x - chartLeft.value, y: y - chartTop.value };
|
||||
e.changedTouches = [tmpe];
|
||||
|
||||
if (e.touches.length == 0) {
|
||||
chartInstance.touchLegend(e);
|
||||
chartInstance.showToolTip(e, {
|
||||
formatter: (item: any) => {
|
||||
return item.name + ':' + item.data;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 触摸开始事件
|
||||
function touchStart(e: any) {
|
||||
if (!chartInstance) return;
|
||||
|
||||
const x = e.mpEvent.changedTouches[0].clientX;
|
||||
const y = e.mpEvent.changedTouches[0].clientY;
|
||||
const tmpe = { x: x - chartLeft.value, y: y - chartTop.value };
|
||||
e.changedTouches = [tmpe];
|
||||
chartInstance.scrollStart(e);
|
||||
}
|
||||
|
||||
// 触摸移动事件
|
||||
function touchMove(e: any) {
|
||||
if (!chartInstance) return;
|
||||
|
||||
const x = e.mpEvent.changedTouches[0].clientX;
|
||||
const y = e.mpEvent.changedTouches[0].clientY;
|
||||
const tmpe = { x: x - chartLeft.value, y: y - chartTop.value };
|
||||
e.changedTouches = [tmpe];
|
||||
chartInstance.scroll(e);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user