FusionCharts 3.2.1 - FusionCharts._fallbackJSChartWhenNoFlash() not working - javascript

I'm using FusionCharts 3.2.1 and I want to render charts in javascript when the flash player is not installed of disabled in browser. I'm calling the method FusionCharts._fallbackJSChartWhenNoFlash() but nothing happen.
function updateChart(chartDataJSON) {
FusionCharts._fallbackJSChartWhenNoFlash();
var currentSwfName = 'MSCombi2D.swf';
if (chartDataJSON.swfName) {
currentSwfName = chartDataJSON.swfName;
}
if (prevSwfName != currentSwfName) {
prevSwfName = currentSwfName;
var contextPath = document.getElementById('contextPath').value;
var swfUrl = contextPath + '/charts/' + currentSwfName;
if (FusionCharts('residenceChart')) {
FusionCharts('residenceChart').dispose();
}
new FusionCharts({
id: 'residenceChart',
swfUrl:swfUrl,
renderAt:'consumptionChartDiv',
dataFormat:'json',
dataSource: chartDataJSON,
registerWithJS: 1,
width: 730,
height: 300,
debugMode: 0
}).render();
} else {
FusionCharts('residenceChart').setJSONData(chartDataJSON);
}
}

Is it mandatory that you stick to FusionCharts 3.2.1? If you upgrade to the latest version (which is free if you are already a customer), this issue will be solved.
Since FusionCharts 3.2.2, the component automatically renders JavaScript charts when Flash Player is not available and you would not need to explicitly call FusionCharts._fallbackJSChartWhenNoFlash(); In fact, this method is removed from the latest API.
However, if you still wish to stick to v3.2.1, I would recommend you first look into the following:
Ensure that you have all the accompanying JavaScript file that was supplied with the FusionCharts package and kept beside the `FusionCharts.js`` file.
Since, the JavaScript charts require additional JS files, they are loaded dynamically when needed. However, it might havae failed for your case; try manually adding the JavaScript files to the page head post inclusion of FusionCharts.js
If you have any JavaScript error on your browsers debug/js console, look for hints from the error message. The FusionCharts documentation and the product forum may help you figure out the cause of the error message.
Just as a precaution, ensure that the swfName passed via JSON is in proper case. FusionCharts 3.2.1 JavaScript charts had a swfUrl case-sensitivity issue.

It seems that the parameters for the FusionCharts Constructor are not in the proper order.
From the FusionCharts Documentation:
var myChart = new FusionCharts("FusionCharts/Column3D.swf", "myChartId", "400", "300", "chartContainer", {dataFormat : "json", dataSource : chartDataJSON});
The above code should work for you.

Related

Reference error: "Workbook" is not defined

I wanna use the next java script code:
function dumpVal(file) {
if (file !=null) {
var wb = new Workbook.create(file);
var sheet = wb.getSheet("Tabelle1");
for (myrow = 1; !isCellEmpty(sheet, myrow, 0); myrow++) {
dataset.setColumnValue("A",getNumericValue(sheet,myrow,0));
dataset.storeResultRow();
}
}
return;
}
but when I am compiling it I receive the next error message: ReferenceError: "Workbook" is not defined.
Can someone to tell me what am I doing wrong?
You recieve the error with the followig line of code:
var wb = new Workbook;
At the point where you create the workbook (new Workbook) you refer to a class called "Workbook". At this point your script dont have a class called Workbook it.
Solution:
You should check your scripts if the class is included and its naming.
Maybe the class is initialized later!
For debug purposes you can try to create the class a line before:
class Workbook{ }
If you recieve an error now because Workbook needs a method called "create", you know that the class is just missing.
I assume that you want to parse excel file from your web application, the library that you are using is for developing add-ins for excel not web application :
Excel JavaScript API programming overview
This article describes how to use the Excel JavaScript API to build add-ins for Excel 2016. It introduces key concepts that are fundamental to using the APIs, such as RequestContext, JavaScript proxy objects, sync(), Excel.run(), and load(). The code examples at the end of the article show you how to apply the concepts.
source :
https://dev.office.com/docs/add-ins/excel/excel-add-ins-javascript-programming-overview
If you want to parse Excel in your web application I suggest to use this library :
https://github.com/SheetJS/js-xlsx
I did not use it so I cant garanty it, but you can look for similar librarys.

Crossrider external js file not loading :PDFJS is not defined

Below are my codes in extension.js. If you look at the codes, I tried different ways to load the file to my extension. No matter what, I always getting
VM3051:15 Uncaught ReferenceError: PDFJS is not defined
Tried with putting the file in different locations.
appAPI.ready(function($) {
console.log("pdf min js loading");
appAPI.resources.includeJS('jspdf.js');
// appAPI.resources.includeJS('js/jspdf.js');
// appAPI.resources.includeRemoteJS('//cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js');
//$.globalEval(appAPI.resources.get('//cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js'));
console.log("done");
setTimeout(function(){
alert(window.location.href);
if(window.location.href.indexOf(".pdf") > -1) {
console.log("its a pdf");
alert("pdf");
var doc = new jsPDF();
}else{
alert($.trim($('div').find('h1,h2,h3,h4,h5,p,span').text()));
}
},6000);
});
Here is the file structure
I cannot modify manifest.json because the extension should be unique for all the browsers not just for chrome.
I'm confused, the two CloudFlare URLs in your code reference the project jsPDF. I would assume the local pdf.js does the same too.
In your code, you're using
PDFJS.getDocument();
This syntax comes from PDF.js which is a totally different project from Mozilla.
If you're sticking with jsPDF, your code should be something like:
var doc = new jsPDF();
doc.text(20, 20, 'Hello world.');
doc.save('Test.pdf');
Or you'll need to include the correct library for PDF.js.
After the edits you've made and your comments, it seems you've switch completely over to jsPDF but you're still getting the same error which clearly mentions PDF.js.
Are you sure you're debugging the correct and last version of your app which is only using jsPDF?
I've setup a small reproduction example on Crossrider using only jsPDF.
The extension.js code is the following:
appAPI.ready(function($) {
console.log("pdf min js loading");
appAPI.resources.includeJS('jspdf.js');
console.log("done");
var doc = new jsPDF();
console.log(doc);
});
When debugging the extension, I'm getting this result:
doc is an object containing an instance of jsPDF which I can later use.
There should be no mention of PDF.js whatsoever. My only guess could be that you're running / debugging a version of your extension still containing references to this project.

Values for global Javascript variable is wrong at the momemt to get it

I am ready with a port from a php mvc application to asp.net mvc (using a lot of javascript and google maps). The application works quite well on my development machine (Win 7 + IIS 7). But the problems start on production server. for some reason i have a javascript file wich is not working well when i am using it from my production server.
i.e. I have my view where i load all the data from db and and after that I put this on an global variable array called global_sites_am. Each row in the array contains attributes like latitud ,longitud and name.... After that this array is readed from the js file called maps.js.
var position = new google.maps.LatLng(global_sites_am[i].latitud,global_sites_am[i].longitud);
addMarker(position,global_sites_am[i].name,i);
For some reason this piece of code work fine on my development machine but it doesn't when i have installed the app on production server.
I.E. On Development machine : global_sites_am[0].latitud = 45,6789566 and global_sites_am[i].longitud=72,69452015
But on Production machine : global_sites_am[0].latitud = 45 and global_sites_am[i].longitud=72
What i am doing wrong?
Update: Here is How I load the value from the db to the javascript file:
global_sites_am[count]=new Object();
global_sites_am[count].name='<%=site.Name%>';
global_sites_am[count].latitud=<%=site.Latitud%>;
global_sites_am[count].longitud=<%=site.Longitud%>;
This is one of my properties:
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Double Latitud
{
get
{
return _Latitud;
}
set
{
OnLatitudChanging(value);
ReportPropertyChanging("Latitud");
_Latitud = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Latitud");
OnLatitudChanged();
}
}
Some debug info from Chrome: http://oi49.tinypic.com/2j4q7p4.jpg. In the image you will see that the values at the moment to load in the page are correct, but at the moment to read them are wrong.
Finally the problem was solved using the next line on the web.config:
globalization uiCulture="en-US" culture="en-US"

Is there a way to AutoFormat (Javascript) code in TestComplete?

So similar to ALt-Shift-F in Netbeans, is there a to do this right in the ide in TestComplete? Not sure if this is possible or if anyone can think of a workaround to autoFormat without leaving the TestComplete window.
I'm trying to get the below solution to work with http://jsbeautifier.org/ for javascript / Jscript code in TestComplete.
Thanks
Great question!
There is no built-in function for that. So, we should not expect any solution to be 100% convenient - it is just not a simple task to modify the current script editor contents (if at all possible). So, whatever you do, it will still be some kind of compromise.
In general, the task is three-fold:
Get the current unit code.
Format the code.
Put the code back to the unit.
According to my understanding, items 1 and 3 can be accomplished only by creating a TestComplete plug-in - accessing editors for project nodes is not an easy thing.
UPDATE: silly me! There is a way to access the script editor code - I've updated the below part.
What will help us avoid switching to a different app, are the Script Extensions:
We create a custom Checkpoint in the form of a Script Extension, and install it to TestComplete. As a result, we get a button on the toolbar that we can click to invoke our code.
In the design time action, we call some code that reads the editor contents, then uses external code formatting functionality, and replaces the editor contents with the formatted code.
It would extremely interesting to see the implementations other TestComplete users can suggest! As a start, I am posting a solution that includes using an external web site to format VBScript code (http://www.vbindent.com/). I know that the starter of the post is probably using JScript, but I have not found a JScript formatter yet.
My solution is a simple Script Extension. I can't post a file here, so I will post the code of the two Script Extension files:
Description file:
<!-- Description.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<ScriptExtensionGroup>
<Category Name="Checkpoints">
<ScriptExtension Name="VBScript Code Indent" Author="SmartBear Software" Version="0.1" HomePage="smartbear.com">
<Script Name="VBIndent.js">
<DesignTimeAction Name="Indent Current VBScript Unit" Routine="DesignTimeExecute"/>
</Script>
<Description>
Indents VBScript code in the currently active unit.
</Description>
</ScriptExtension>
</Category>
</ScriptExtensionGroup>
Code file:
// VBIndent.js
function DesignTimeExecute()
{
if (CodeEditor.IsEditorActive)
{
var newCode = IndentVBSCode_Through_VBIndent(CodeEditor.Text);
if (null == newCode)
return;
CodeEditor.Text = newCode;
}
}
function IndentVBSCode_Through_VBIndent(codeToIndent)
{
var URL_VBIndent = "http://www.vbindent.com/?indent";
var httpObj = Sys.OleObject("MSXML2.XMLHTTP");
httpObj.open("POST", URL_VBIndent, false);
httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpObj.send("thecode=" + escape(codeToIndent));
var responseText = httpObj.responseText;
// Extract the indented code from the response
var rx = /<textarea name=\"thecode\".*?>((.*\n)*?)<\/textarea>/;
matches = rx.exec(responseText);
if (null == matches)
{
return null;
}
codeIndented = matches[1];
return codeIndented;
}
After you create these files, and put them to something like "\Bin\Extensions\ScriptExtensions\VBIndent", and click "File | Install Script Extensions | Reload", you will see a new "Indent Current VBScript Unit" item in the custom checkpoints drop-down button on the Tools toolbar. Clicking the element will format the VBScript code in the currently active editor.
So, this is to give a clear idea of what a solution can look like. Better suggestions are welcome! Share your thoughts!
FYI
I've done. Based on your posts.
JSFormat.tcx
https://drive.google.com/uc?export=download&id=0B1x_73bHRc2Jcm8wbTJ2dUpZQTQ
To install the extension copy attached file JSFormat.tcx to C:\Program Files (x86)\SmartBear\TestComplete 10\Bin\Extensions\ScriptExtensions
To use view next image:
https://drive.google.com/uc?export=download&id=0B1x_73bHRc2Jc3RuLXFpTnlCSnc
Regards

Can Indy run Javascript?

There is a software product called AnyChart which is great for embedding Flashed based charts in web pages. AnyCharts can also export to PNG file format. Here is an example:
<script type="text/javascript" language="javascript">
//<![CDATA[
var chart = new AnyChart('http://www.mysite.com/swf/AnyChart.swf');
chart.width = 600;
chart.height = 300;
chart.setXMLFile('http://www.mysite.com/anychart.xml');
chart.addEventListener("draw", function() { saveChartAsImage(chart); });
chart.write("content-box");
//]]>
</script>
My ultimate goal is to make a automated service to export the AnyChart charts to PNG format. So I made a service with Indy which calls pages containing the AnyChart javascript. But the problem seems to be that Indy cannot execute the javascript.
Is there a way to enable Indy to execute javascript?
No, Indy does not execute Javascript. You may have also noticed that it doesn't parse or display HTML, and it doesn't run Flash, either. Indy does network protocols.
You could import the Microsoft Script Control ActiveX object and have that run your Javascript. If you need details on that, post a new question.
You don't have to use Indy for this. If you want you can use TWebBrowser.
IHTMLWindow2 interface has execScript function. So may be you can :
var
Doc : IHTMLDocument2;
Win : IHTMLWindow2;
aBrowser : TWebBrowser;
//...
begin
//...
Doc := aBrowser.Document as IHTMLDocument2;
Win := Doc.parentWindow;
Win.execScript('alert(SomeMessage);', 'JavaScript');
end;
Did you try vcl FOR THE web (aka Intraweb atozed) ?
There is a teechart version wich is quite useful, you can also execute "external" javascript code within any of the TiwForms of your web app (the exact same code you are using now).
Post a new question if you need to and I'll be glad to help.

Categories

Resources