这个问题可以通过使用billboard.js库提供的tooltip功能来解决。具体的方法是,在timeseries图表上加入一个tag,并在tooltip中显示该tag的信息。
示例代码如下:
let chart = bb.generate({ data: { x: "x", columns: [ ["x", "2018-01-01", "2018-01-02", "2018-01-03", "2018-01-04", "2018-01-05"], ["data1", 30, 200, 100, 400, 150], ["data2", 50, 20, 10, 40, 15], ["tag", "Your tag here", "Your tag here", "Your tag here", "Your tag here", "Your tag here"] ], types: { data1: "line", data2: "line", tag: "line" }, colors: { data1: "#000000", data2: "#ff00ff", tag: "#000000" } }, axis: { x: { type: "timeseries", tick: { format: "%Y-%m-%d" } } }, tooltip: { format: { title: function(d) { return d3.timeFormat("%Y-%m-%d")(d); }, value: function(value, ratio, id, index) { let format = id === "tag" ? d3.format("") : d3.format(".2f"); return format(value); } } } });
这段代码中,我们在columns数组中添加了一个tag,其值为用户自定义信息;在types中将tag类型设置为line,并在colors中设置其颜色;最后,需要在tooltip的format中针对tag类型特殊处理,将其格式化输出。
运行该代码,我们可看到一个带有tag信息的timeseries图表,并在tooltip中显示了该tag的信息。