如何在高图工具提示中绑定动态数据

How to bind dynamic data in highcharts Tooltip

本文关键字:绑定 动态 数据 工具提示 高图      更新时间:2023-09-26

现在我使用Highcharts。谁能回答一下如何在高图的工具提示中绑定动态数据?我已经从数据库中绑定了数据,我想在图表中显示到序列的数据数组。

    js.Append("series: [{name: 'Average Price',type: 'line',color: 'blue',");
    js.Append("data:[");
    for (int i = 0; i < dt.Rows.Count; i++)
   {
    js.Append("[" + Decimal.Parse(dt.Rows[i]["Test"].ToString().Trim()) + ],");
   }
    js.Append("]]}); ");

还好。

但是我还想在工具提示中显示数据库中的另一个数据为动态的。我不知道如何传递数据给工具提示。

现在我得到了解决方案使用http://api.highcharts.com/hilitock#series。在一系列高图中,我们可以添加两个以上的动态值。如果序列数据数组中只有一个数据,则假定为y轴值;如果两个数据在序列的数据数组中,则假定为x轴值和y轴值。但是在数据数组中有两个以上的数据,我们可以自定义我们想要添加的值,然后我们可以在工具提示中动态地使用这些值。

    js.Append("tooltip: {crosshairs: true,shared: true,formatter: function() {");
            js.Append("var s = '';$.each(this.points, function(i, point) {");
            js.Append("s += '<b>#' + this.point.name +': PSF -'+ this.point.y +' :'+ this.point.test+ '</b>';");
            js.Append("});return s;}")
 js.Append("series: [{name: 'Average Price',type: 'line',color: 'blue',");
    js.Append("data:[");
    for (int i = 0; i < dt.Rows.Count; i++)
   {
js.Append("{ name:'" + dt.Rows[i]["name"].ToString().Trim()+ "',test:'" + dt.Rows[i]["test"].ToString().Trim()+ "',y:" + dt.Rows[i]["value"].ToString().Trim()+ ",color:'#DC3811'},");
   }
    js.Append("]]}); ");

希望对使用highcharts的人有所帮助