You need to sign in to do that
Don't have an account?
bbrady
Looking for code samples that incorporate visualizations from "AnyChart"
I looking for code samples that will help me add visualizations from http://www.anychart.com to my VF pages.
I've had some success using the google visualizations codeshare, but most of the visualizations I'd like to use support XML but not JSON. I thought I'd check the discussion boards before I set about reinventing the wheel.
Thanks!
Bill
Solution: I was never successful at passing the URL of a VF page to anychart in the manner Ron originally suggested (i.e. modeling the KML generation in the GoogleEarth codeshare) but was ultimately successful using XMLStreamWriter within a controller extension to pass an XML string to the VF page that called AnyChart.
<apex:page standardController="CIP_Project__c" extensions="ganttProjectExt" showheader="true" sidebar="false"> <html> <head> <apex:includeScript value="{!$Resource.AnyChartJS}"/> </head> <body> <script type="text/javascript"> var chart = new AnyChart("{!$Resource.AnyGanttSWF}"); chart.width = 900; chart.height = 400; chart.setData('{!xmlOutput}'); chart.write(); </script> </body> </html> </apex:page>
All Answers
there is code to generate xml using Apex out on codeshare, how do you pass the XML into the flash component, is this done with a URL ? can you pass an authenticated URL ?
can you host the SWF on Force.com in a static resource ?
let me know if you get stuck, this is an interesting technology combo.
Are you referring to XMLStreamWriter, XMLDomParser or something else?
XMLStreamWriter looks like it will do the job (I'm guessing, here). I've also seen a VF page (KML.PAGE - in the Google Maps/Earth codeshare) that appears to demonstrate an approach that could result in something usable. Since this is my first foray into XML, I guess I was looking for some guidance as to the easiest way generate the XML. XMLStreamWriter looks like is was designed for such a task unless I misunderstad its purpose.
As to your question about how to pass the XML to the flash component... the following from AnyChart makes me think the answer to your question is yes. (i.e. hosting the SWF as a static resource is the correct approach).
the KML page is a good example of using Visualforce to generate raw XML output ( not a page to view) , i suggest that approach.
This JS code
chart.setXMLFile('./anychart.xml');
could easily be something like this
chart.setXMLFile('/apex/generateChartXML');
since you don't have access to a file system unless you create and consume documents on the fly, which is not best practice.
Note: this could fall down if the chart SWF assumes that it can perform a file open on the param.
Is there another option to set XML, something like setXML String or setXML URL ? Those would be better.
Thanks for the direction on generating the raw XML. I shall proceed down that path.
I see from their doc that I can get an XML String from server using AJAX and then set it to the chart. which I assume is the functional equivalent of the "setXML URL" that you asked about.
It seems pretty straightforward once I get my XML in order. Its a nice visualization library - if not a bit expensive. I see that 0racle has licensed it for their applikation xpress. It would be nice to see SFDC improve their visualization capabilities in this way.
Thanks for your help!
Bill
After uploading as static resources, their JS code, SWF and XML, the promised chart displayed (yeah!)
The next step was to see if I could get it to display XML generated using a VF page (/apex/AssetXML2):
This time I got an XML parser error from AnyChart. However the XML I used was the same XML that I uploaded as a static resource, which was cut and paste from their demo code. All I did is wrap it in <apex:page> tags. The controller wasn't used in this case as all the text was straight cut and paste. Here is the VF page I used to generate the XML:
My question at this point is how do I take the XML constructed by this VF page and package it up as a string rather than passing the file path?
Ron,
My problem doesn't appear to be related to the code for the charting library, but rather with the way I am atttempting to reference the XML file (or perhaps a problem with my load function - but it isn't raising andy errors that I can tell).The following code executes correctly referencing the XML file uploaded as a static resource:
<script type="text/javascript" language="javascript">
loadXMLDoc("{!$Resource.AnyChartXML}");
var elements=xmlDoc.getElementsByTagName("text");
document.write(elements[0].tagName + '<br>');
</script>
However neither of the next to code blocks, do. The XML is identical. It isn't even generated. Its simply cut and past into a VF page as you'll see in the last code block.
<script type="text/javascript" language="javascript">
loadXMLDoc("{!$Page.AnyChartXML}");
var elements=xmlDoc.getElementsByTagName("text");
document.write(elements[0].tagName + '<br>');
</script>
<apex:page showHeader="false">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" language="javascript">
function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e) {alert(e.message)}
return(null);
}
</script>
</head>
<body>
<script type="text/javascript" language="javascript">
loadXMLDoc{'/apex/AssetsXML');
var elements=xmlDoc.getElementsByTagName("text");
document.write(elements[0].tagName + '<br>');
</script>
</body>
</html>
</apex:page>
And the contents of /apex/AnyChartXML:
<apex:page showheader="false" contenttype="text/xml; charset=UTF-8">
<anychart>
<charts>
<chart plot_type="CategorizedHorizontal">
<data>
<series name="Year 2003" type="Bar">
<point name="Department Stores" y="637166" />
<point name="Discount Stores" y="721630" />
<point name="Men's/Women's Specialty Stores" y="148662" />
<point name="Juvenile Specialty Stores" y="78662" />
<point name="All other outlets" y="90000" />
</series>
</data>
<chart_settings>
<title>
<text>Sales of ACME Corp.</text>
</title>
<axes>
<y_axis>
<title>
<text>Sales</text>
</title>
</y_axis>
<x_axis>
<labels align="Outside" />
<title>
<text>Retail Channel</text>
</title>
</x_axis>
</axes>
</chart_settings>
</chart>
</charts>
</anychart>
</apex:page>
Solution: I was never successful at passing the URL of a VF page to anychart in the manner Ron originally suggested (i.e. modeling the KML generation in the GoogleEarth codeshare) but was ultimately successful using XMLStreamWriter within a controller extension to pass an XML string to the VF page that called AnyChart.
<apex:page standardController="CIP_Project__c" extensions="ganttProjectExt" showheader="true" sidebar="false"> <html> <head> <apex:includeScript value="{!$Resource.AnyChartJS}"/> </head> <body> <script type="text/javascript"> var chart = new AnyChart("{!$Resource.AnyGanttSWF}"); chart.width = 900; chart.height = 400; chart.setData('{!xmlOutput}'); chart.write(); </script> </body> </html> </apex:page>
Hi is there a way to remove header?
With Regards
Palak Agarwal