DOTNET Highchart添加JavaScript函数 [英] Dotnet Highchart add javascript function

查看:139
本文介绍了DOTNET Highchart添加JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在生成的图表上添加一个点击事件。我有以下code:

I want to add a click event on my generated chart. I have the code below:

 Highcharts chart = new Highcharts("chart");


chart.InitChart(new DotNet.Highcharts.Options.Chart { DefaultSeriesType = ChartTypes.Bar, Height = 500 })

   .SetTitle(new Title { Text = "Nombre de resultat par mois" })
    // .SetSubtitle(new Subtitle { Text = "Accounting" })
   .SetXAxis(new XAxis { Categories = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" } })
   .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Nombre de resultats" } })
   .SetTooltip(new Tooltip
   {
       Enabled = true,
       Formatter = @"function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y; }"
   })
   .SetPlotOptions(new PlotOptions
   {

       Line = new PlotOptionsLine
       {
           Point = new PlotOptionsLinePoint { Events = new PlotOptionsLinePointEvents { Click = "ChartClickEvent" } },
           DataLabels = new PlotOptionsLineDataLabels
           {
               Enabled = true

           },
           EnableMouseTracking = false

       }

   })
  .SetSeries(new Series { Name = "MySeries", Data = new Data(new object[] { 29.9, 71.5, 106.4, 129.2, 144.0, 148.5, 216.4, 194.1, 95.6, 54.4, 55, 66 }) })
  .AddJavascripFunction("ChartClickEvent", @"alert('yyyy'); ");

一切都只是从单击事件工作以及 ChartClickEvent 。当我点击图表上,它只是给没有结果 - 而不是显示警报('YYYY')

Everything is working well except from the click event ChartClickEvent. When I click on the chart, it just gives no result - instead of showing alert('yyyy').

推荐答案

可以做到这一点,例如(基本警报):

You can do this, for instance (basic alert):

Highcharts chart = new Highcharts("chart")
   .SetPlotOptions(new PlotOptions
   {
       Series = new PlotOptionsSeries
       {
           Point = new PlotOptionsSeriesPoint
           {
               Events = new PlotOptionsSeriesPointEvents { Click = "ChartClickEvent" }
           }
       }
   })
  .AddJavascripFunction("ChartClickEvent", @"alert(this.series.name);", new string[] { "event" });

这篇关于DOTNET Highchart添加JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆