我正在尝试在vb.net中使用highchart。当我启动 ScriptManager.RegisterClientScriptBlock chrome返回 未捕获的SyntaxError:意外的令牌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中,则可以正常工作。 如果我将代码直接粘贴到函数javascript中的aspx文件中,它就可以工作。
任何想法??
答案 0 :(得分:0)
问题是' \ 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 &
"});"