示例中只有静态赋值,这个问题困扰了很久,最终结果
page外仍然定义initChart
let chart = null;
function initChart(canvas, width, height, F2) {
var pages = getCurrentPages();
var currPage = pages[pages.length - 1]
var data = currPage.data.myData
chart = new F2.Chart({
el: canvas,
width,
height
});
chart.source(data);
chart.tooltip({
custom: true, // 自定义 tooltip 内容框
onChange(obj) {
const legend = chart.get('legendController').legends.top[0];
const tooltipItems = obj.items;
const legendItems = legend.items;
const map = {};
legendItems.map(item => {
map[item.name] = Object.assign({}, item);
});
tooltipItems.map(item => {
const { name, value } = item;
if (map[name]) {