如何使yaxis ticks成为flot图中的超链接

时间:2013-09-25 14:52:36

标签: flot

我正在创建一个带有flot库的折线图,并且在y轴上我的所有刻度都是缩写,我想把所有的刻度都作为超链接,所以在打开页面时他们会得到更多有关abb的详细信息。

这是我制作y轴的代码:

  var ranks = Context.CreateDataContext().Ranks.OrderBy(c => c.RankID);
        var yaxis = new StringBuilder(" { yaxis : {ticks:[");
        foreach (var item in ranks)
        {
            if (item.RankID == 0)
                   yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "None");
                if (item.RankID == 1)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "AMB");
                if (item.RankID == 2)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "BA");
                if (item.RankID == 3)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "SA");
                if (item.RankID == 4)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "GA");
                if (item.RankID == 5)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "PA");
                if (item.RankID == 6)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "RA");
                if (item.RankID == 7)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "EA");
                if (item.RankID == 8)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "DA");
                if (item.RankID == 9)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "DDA");
                if (item.RankID == 10)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "TDA");
                if (item.RankID == 11)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "PDA");
                if (item.RankID == 12)
                    yaxis.AppendFormat(@"[{0},'{1}'],", item.RankID, "CDA");
        }
        yaxis.Append("]}}");

我想制作“AMB”,“BA”,“SA”,“GA”....所有这些都是链接或工具提示..

谢谢!

1 个答案:

答案 0 :(得分:3)

您可以尝试tickFormatter选项来自定义刻度标签(有关详细信息,请参阅documentation)。一个起点:

function formatter(val, axis) {
    return '<span title="' + getFullNameForAbbreviation(val) + '">' + val + '</span>';
}

您必须添加该函数才能从缩写中获取全名。