显示内容设置的Canvasjs工具提示,但在第一次鼠标移动后被替换

时间:2017-04-03 23:59:14

标签: javascript jquery canvasjs

我更改了CanvasJS图的工具提示内容。它像文档一样完成,并且有效。但是最近(确切地说不确定)我发现无论我在图形选项中写入ToolTip.content,它只在我第一次将鼠标移到图形上时显示,下次工具提示完全替换为默认值。这是我的图表代码:

var options_seg = {
            title: {
                text: ""
            },
            culture: "en",
            zoomEnabled: true,
            exportEnabled: true,
            animationEnabled: false,
            axisX: {
                labelFontSize: 11,
                gridColor: "Silver",
                tickColor: "silver"
            },
            axisY: {
                title: "Formula values",
                titleFontSize: 14,
                labelFontSize: 11,
                gridColor: "Silver",
                tickColor: "silver",
                lineColor: "#C24642"
            },
            toolTip: {
                shared: true,
                content: function (e)
                {
                    var ret = "";
                   if (e.entries[ 0 ].dataPoint.label)
                        ret = "<b>" + e.entries[ 0 ].dataPoint.label + "</b><br>";
                    else
                    {
                        if (e.entries[ 0 ].dataPoint.x)
                        {
                            if (e.entries[ 0 ].dataSeries.xValueType == "dateTime")
                                ret = "<b>" + $.format.date(e.entries[ 0 ].dataPoint.x, "yyyy-MM-dd HH:mm") + "</b><br>";
                            else
                                ret = "<b>" + e.entries[ 0 ].dataPoint.x + "</b><br>";
                        }
                    }

                    var show_vals = [];
                    for (var t = 0; t < e.entries.length; t++)
                        if (e.entries[ t ].dataSeries.visible)
                            show_vals[ show_vals.length ] = {col: e.entries[ t ].dataSeries.color, key: e.entries[ t ].dataSeries.name, v: e.entries[ t ].dataPoint.y};

                    customSortObjByIntParameter(show_vals, "v", false);

                    var max = Math.min(50, show_vals.length);
                    for (t = 0; t < max; t++)
                        ret += "<div style='white-space:nowrap; font-size:11px; line-height:13px;'><span style='color:" + show_vals[ t ].col + "'>" +
                            show_vals[ t ].key + "</span> : <b>" + show_vals[ t ].v + "</b></div>";

                    return ret;
                }
            },
            data: graphs_seg,
            legend: {
                fontSize: 11,
                verticalAlign: "center",
                horizontalAlign: "right",
                cursor: "pointer",
                itemclick: function (e)
                {
                    if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible)
                    {
                        e.dataSeries.visible = false;
                    }
                    else
                    {
                        e.dataSeries.visible = true;
                    }
                    e.chart.render();
                }
            }
        };

$chart_holder_seg.CanvasJSChart(options_seg);
$chart_holder_seg.CanvasJSChart().render();

1 个答案:

答案 0 :(得分:0)

当我更换

时开始工作
       toolTip: {
            shared: true,
            content: function (e) ...

       toolTip: {
            shared: true,
            contentFormatter: function (e) ...

不知道,为什么以前工作过。