【问题标题】:Unexpected token ILLEGAL with hightcharts带有高图表的意外令牌非法
【发布时间】:2014-09-18 13:01:50
【问题描述】:

我正在尝试在 vb.net 中使用 highchart。当我启动 ScriptManager.RegisterClientScriptBlock chrome 返回 Uncaught SyntaxError: Unexpected token ILLEGAL

VB代码:

    Dim Script As String
    Script = "$(function () {\n"
    Script += "$('#container').highcharts({\n"
    Script += "chart: {\n"
    Script += "type: 'line'\n"
    Script += "},\n"
    Script += "title: {\n"
    Script += "text: 'Consumos por semanas'\n"
    Script += "},\n"
    Script += "subtitle: {\n"
    Script += "text: 'Kwh/Módulos-Piezas'\n"
    Script += "},\n"
    Script += "xAxis: {\n"
    Script += "categories: ['25', '26']\n"
    Script += "},\n"
    Script += "yAxis: {\n"
    Script += "title: {\n"
    Script += "text: 'Kwh'\n"
    Script += "}\n"
    Script += "},\n"
    Script += "plotOptions: {\n"
    Script += "line: {\n"
    Script += "dataLabels: {\n"
    Script += "enabled: true\n"
    Script += "},\n"
    Script += "enableMouseTracking: false\n"
    Script += "}\n"
    Script += "},\n"
    Script += "series: [{\n"
    Script += "name: 'cach',\n"
    Script += "data: [1.1003, 6.5265]},\n"
    Script += "]\n"
    Script += "});\n"
    Script += "});"

    Dim popupScript = "<script type='text/javascript'>" + Script + "</script>"
    ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "onload", popupScript, False)

aspx代码:

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="../../scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

如果我将脚本变量导出到 txt 文件并用换行符替换 \n 并将代码放入 hightchart demo code,它可以工作。 如果我将代码直接粘贴到 aspx 文件中的函数 javascript 中,它可以工作。

有什么想法吗??

【问题讨论】:

    标签: asp.net vb.net


    【解决方案1】:

    问题在于 '\n' 不是在 VB 字符串中定义新行的正确方法。这在 C# 中有效,但在 VB.NET 中无效。您想使用 vbCrLf 常量。

    此外,如果可以在一个语句中定义字符串,则不应使用重复连接来构建字符串。

      Dim Script As String = "$(function () {" & vbCrLf &
           "$('#container').highcharts({" & vbCrLf &
           "chart: {" & vbCrLf &
           "type: 'line'" & vbCrLf &
           "}," & vbCrLf &
           "title: {" & vbCrLf &
           "text: 'Consumos por semanas'" & vbCrLf &
           "}," & vbCrLf &
           "subtitle: {" & vbCrLf &
           "text: 'Kwh/Módulos-Piezas'" & vbCrLf &
           "}," & vbCrLf &
           "xAxis: {" & vbCrLf &
           "categories: ['25', '26']" & vbCrLf &
           "}," & vbCrLf &
           "yAxis: {" & vbCrLf &
           "title: {" & vbCrLf &
           "text: 'Kwh'" & vbCrLf &
           "}" & vbCrLf &
           "}," & vbCrLf &
           "plotOptions: {" & vbCrLf &
           "line: {" & vbCrLf &
           "dataLabels: {" & vbCrLf &
           "enabled: true" & vbCrLf &
           "}," & vbCrLf &
           "enableMouseTracking: false" & vbCrLf &
           "}" & vbCrLf &
           "}," & vbCrLf &
           "series: [{" & vbCrLf &
           "name: 'cach'," & vbCrLf &
           "data: [1.1003, 6.5265]}," & vbCrLf &
           "]" & vbCrLf &
           "});" & vbCrLf &
           "});"
    

    【讨论】:

    • 非常感谢...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 2015-10-19
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多