dimple.js scatterplot复制轴标签

时间:2015-06-10 23:31:26

标签: javascript d3.js data-visualization dimple.js

使用dimple.js,我使用下面的代码渲染散点图。这样可以正常工作,但是当我将鼠标悬停在任意点上时,x和y值会显示两次,一次显示为十进制,低于百分比。我怎样才能简单地在悬停弹出窗口中保留x,y值百分比?另外,有没有办法在悬停弹出窗口中显示其他项目?
以下是演示该问题的小提琴:http://jsfiddle.net/dizzy0ny/ch2187dd/52/

var svg = dimple.newSvg("#chartContainer", 600,600);
var myChart = new dimple.chart(svg);
myChart.setBounds(90, 35, 480, 400)
xAxis = myChart.addMeasureAxis("x", "x");
yAxis = myChart.addMeasureAxis("y", "y");
xAxis.showGridlines = true;
xAxis.tickFormat = '.1%'
yAxis.tickFormat = '.1%'
s1 = myChart.addSeries(["x","y","group"], dimple.plot.bubble, [xAxis, yAxis]);
s1.data = data_scatter

s2 = myChart.addSeries(["y","group"], dimple.plot.line, [xAxis, yAxis]);
s2.data = data_ser1      

myChart.addLegend(90, 480, 330, 20, "left");
myChart.draw();

1 个答案:

答案 0 :(得分:1)

根据此处的文档:http://dimplejs.org/adhoc_viewer.html?id=adhoc_bar_custom_tooltips

您可以更改默认工具提示,如下所示:

s1.getTooltipText = function (e) {
    return [
        "This is a custom tooltip!",
        "X value: %" + (e.aggField[0]*100).toFixed(2), 
        "Y value: %" + (e.aggField[1]*100).toFixed(2),
        "Group: " + e.aggField[2]
    ];
};

在此处查看您的更新小提琴:http://jsfiddle.net/ch2187dd/55/

另外,尽量不要忘记那些分号! :)