Echarts:自定义悬浮框的内容

本代码实现的样式是当标题长度大于20位的时候,让标题折行显示

formatter的回调参数params有时候是数组有时候是对象,需要自己打印来看

tooltip: {
    // " 是小圆点的样式
    formatter: function(params) {
                        const title = params[0].name;
                        let title1 = "";
                        let title2 = "";
                        let results = "";
                        if (title.length > 20) {
                            title1 = title.slice(0, 20);
                            title2 = title.slice(20);
                        } else {
                            title1 = title;
                        }
                        params.forEach(item => {
                            results +=
                                "" +
                                item["seriesName"] +
                                ":" +
                                item["value"] +
                                "
"; }); if (title2.length) { return ( title1 + "
" + title2 + "
" + results ); } else { return title1 + "
" + results; } } }

你可能感兴趣的:(echarts)