Reputation: 9
I have a classic ASP website, we have taken the Flash components to generate charts to incorporate this functionality through a JavaScript library.
On the same page ASP, we read text files, the data is saved in arrays and these must be passed to the javascript function. This code is not a function, because depending on the selected menu, different files are read. It is a very extensive code.
<%
···
ReDim LisOp (numop)
ReDim Lisco (numop)
ReDim LisVo (numop)
aux = options
for i = 1 to numop
p = InStr (aux, ",")
if p> 0 Then
LisOp (i - 1) = Left (aux, (p - 1))
Right aux = (aux, (Len (aux) - p))
else
LisOp (i - 1) = aux
aux = ""
end if
Next
···
%>
In these variables LisOp, Lisco, LisVo we have data. The problem is when I want to pass this information to javascript:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV = "refresh" CONTENT = "<% = TieRefresco%>">
<script type="text/javascript" src="http://www.google.com/jsapi"> </ script>
<script language="JavaScript">
google.load ('visualization', '1 ', {' packages': ['table', 'corechart']});
google.setOnLoadCallback (draw);
function draw () {
var options = {title:'',
legend: {position: "none"},
hAxis: {textstyle: {color: 'black', fontName: 'Arial Black', size: 16}}
};
// Create data table object
var google.visualization.DataTable datat = new (); / / DataTable Roles
// Define columns
datat.addColumn ('string', '<% = tOpciones%>'); / / Implicit domain column.
datat.addColumn ('number', '<% = tVotos%>'); / / Implicit data column.
datat.addColumn ({type: 'string' role: 'style'});
datat.addColumn ({type: 'string' role: 'annotation'});
for (var i = 0; i << numop%% => -1, i + +) {
datat.addRow (['OP1', 450, 'color: green', '450 ']);
}
···
</ Script>
</ HEAD>
<BODY>
···
In the example I've left fixed values to the function addRow, but I need to pass the arrays created in Visual Basic script “LisOp, LisVo, LisCo”. With fixed values runs perfect. Then I put code examples I've tried but have not worked to pass array values to function addRow:
I tried the VBArray (arrayObj) toArray () function; but it gives me an error and I did not make the graphic:
var arrayObj;
var jsArray;
arrayObj = LisOp
jsArray = VBArray (arrayObj) toArray ().;
for (var i = 0; i << numop%% => -1, i + +) {
datat.addRow ([jsArray[i], 450, 'color: green', '450 ']);
}
I tried to make the loop for VBScript within the draw() function but does not work:
<% For i = 0 to numop%>
datat.addRow ([<%=LisOp(i)%>, <%=LisVo(i)%>, <%=lisCo(i)%>, <%=LisVo(i)%>])
<% Next%>
Any idea?
Upvotes: 0
Views: 598
Reputation: 70923
Maybe, your problem is the js quoting of the generated data
<% For i = 0 to numop %>
datat.addRow (['<%=LisOp(i)%>', <%=LisVo(i)%>, '<%=lisCo(i)%>', '<%=LisVo(i)%>']);
<% Next %>
Upvotes: 1
Reputation: 23863
I've only had do this once before and I played with a bunch of different options trying to find something robust and reliable.
In the end, I had to break down and use a loop in VBA to deconstruct the object, calling a function in JavasScript to reconstruct it.
Forgive this syntax, I haven't worked with VBA for along time -- it is sure to be wrong
for i = 1 to numop
jsSetLisOp (i, LisOp(i))
jsSetLisCo (i, LisCo(i))
Next
Javascript
// Set up our magic function
var wrapper = (function() {
var arr = [];
function jsSetLisOp(idx, val) {
var o = arr[i] || {};
o.LisOp = val;
}
function jsSetLisCo(idx, val) {
var o = arr[i] || {};
o.LisCo = val;
}
return {
jsSetLisOp: jsSetLisOp,
jsSetLisCo: jsSetLisCo
arr = arr;
};
}());
// Move this to a global level so we can share them with VBA
var jsSetLisOp = wrapper.jsSetLisOp;
var jsSetLisCo = wrapper.jsSetLisCo;
var jsobject = wrapper.arr;
Upvotes: 1