账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    求解:接完接口后echarts饼图和线图这种联动和共享数据集的图中饼图必须鼠标滑过或者点击才会出现?
    48
    0
    刚进页面的样子鼠标滑过这两块,饼图才会出现父组件<ShareDataset :chartId="'chartId1'" :chartData="chartData1"></ShareDataset>子组件 <div class="charts"> <div :id="chartId" :style="{ height: height, width: width }"></div> </div><script>import * as echarts from "echarts"import { onMounted, computed, toRefs, watch } from "vue"export default { props: { chartId: { type: String, default: () => { return "chartId" } }, chartData: { type: Array }, height: { type: String, default: "100%" }, width: { type: String, default: "100%" } }, setup(props) { const { chartData, chartId } = toRefs(props) const setOptions = computed(() => { let option = { legend: { textStyle: { fontSize: 12, color: "#e8fffb" } }, tooltip: { trigger: "axis", showContent: false }, dataset: { source: props.chartData // source: [ // ["product", "2012", "2013", "2014", "2015", "2016", "2017"], // 线图x轴下标名 // ["220kV", 56.5, 82.1, 88.7, 70.1, 53.4, 85.1], // ["110kV", 51.1, 51.4, 55.1, 53.3, 73.8, 68.7], // ["35kV", 40.1, 62.2, 69.5, 36.4, 45.2, 32.5], // ["其它", 25.2, 37.1, 41.2, 18, 33.9, 49.1] // ] }, xAxis: { type: "category", axisLine: { lineStyle: { color: "#e8fffb" // width: 1 //这里是为了突出显示加上的 } } }, yAxis: { gridIndex: 0, splitLine: { lineStyle: { // 使用深浅的间隔色 color: ["#e8fffb"] } }, nameTextStyle: { color: ["#e8fffb"] }, axisLine: { lineStyle: { color: "#e8fffb", width: 1 //这里是为了突出显示加上的 } } }, grid: { top: "55%", bottom: "12%" }, series: [ { type: "line", smooth: true, seriesLayoutBy: "row", emphasis: { focus: "series" } }, { type: "line", smooth: true, seriesLayoutBy: "row", emphasis: { focus: "series" } }, { type: "line", smooth: true, seriesLayoutBy: "row", emphasis: { focus: "series" } }, { type: "line", smooth: true, seriesLayoutBy: "row", emphasis: { focus: "series" } }, { type: "pie", id: "pie", radius: "30%", center: ["50%", "30%"], emphasis: { focus: "self" }, label: { formatter: "{b}: {@2012} ({d}%)" }, encode: { itemName: "product", // value: "2012", // tooltip: "2012" } } ] } return option }) // 创建图表 function initChart() { echarts.init(document.getElementById(props.chartId)).dispose() // 销毁实例 let myChart = echarts.init(document.getElementById(props.chartId)) window.addEventListener("resize", () => { myChart.resize() }) setTimeout(function () { myChart.on("updateAxisPointer", function (event) { const xAxisInfo = event.axesInfo[0] if (xAxisInfo) { const dimension = xAxisInfo.value + 1 myChart.setOption({ series: { id: "pie", label: { formatter: "{b}: {@[" + dimension + "]} ({d}%)" }, encode: { value: dimension, tooltip: dimension } } }) } }) // 使用刚指定的配置项和数据显示图表。 myChart.setOption(setOptions.value, true) }) } onMounted(() => { initChart() }) watch([chartData, chartId], () => { initChart() }) return { setOptions, initChart } }}</script>
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 南顾生烟 普通会员 1楼

      在ECharts的饼图和线图中,你可以在需要展示数据集时设置type属性为value,然后在相应的图表事件中,通过判断鼠标是否滑过或者点击来触发显示数据集的事件。

      例如:

      ```javascript var option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [{ name: 'ECharts Series', type: 'pie', radius: '55%', data: [{ value: 20, label: 'Option 1' }, { value: 30, label: 'Option 2' }, { value: 40, label: 'Option 3' }] }] };

      option.type = 'value'; echarts.init(document.getElementById('main'));

      var chart = echarts.init(document.getElementById('main'));

      // 触发显示数据集的事件 chart.setOption(option);

      // 触发鼠标滑过或点击事件 chart.on('mousemove', function () { console.log('鼠标移动的距离: ' + chart.getOption().x); }); ```

      在这个例子中,当鼠标在图表的范围内滑动时,都会触发显示数据集的事件,当鼠标在图表的某个点上点击时,也会触发显示数据集的事件。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部