Integrate FusionChart in android application?

二次信任 提交于 2019-12-08 02:20:23

问题


I want to integrate fusionchart in android native application (not phonegap).I have write code for it as below

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview =(WebView) findViewById(R.id.web);
String summary = 
"<html>"+
"<head>        "+
" <title>My First chart using FusionCharts XT - Using JavaScript</title>      "+
"<script type=\"text/javascript\" src=\"FusionCharts/FusionCharts.js\"></script>"+
"</head> "+  
"<body>"+     
" <div id=\"chartContainer\">FusionCharts XT will load here!</div>"+          
"<script type=\"text/javascript\">"+
" var myChart = new FusionCharts( \"FusionCharts/Column3D.swf\",\"myChartId\", \"400\",\"300\", \"0\", \"1\" );"+
"myChart.setXMLUrl(\"Data.xml\");"+
"myChart.render(\"chartContainer\");"+      
"</script>"+      
"</body>"+ 
 "</html>";
webview.loadDataWithBaseURL(null, summary, "text/html", "utf8", null);
}

please anybody tell me what is problem. I dont know how to give exact FusionCharts/FusionCharts.js path and no idea about Column3D.swf file.

Where can i get those files.

even this html code not working in my pc browser.

and I want to make bar chart in android application using only fusionchart !!!


回答1:


You would need to download the FusionCharts XT Download Package in order to receive the necessary JavaScript and SWF files, provided in the "Charts" folder of the Download Package, that would let you render FusionCharts. You may download the evaluation package from here.

Also, please check here for the detailed process to create your first chart on the browser.

FusionCharts is expected to work perfectly on the native Android apps, provided all the other criteria mentioned here to render the JavaScript charts (Android 3.0 and above) and Flash charts are fulfilled.

FusionCharts does not have any native API to render the charts in Android apps. Hence, you would need to use some 3rd party mobile development framework like, PhoneGap, UIWebView, etc. and the API controls they provide, to achieve the same.

There is no sample for rendering FusionCharts in native Android apps, however, there is a similar implementation for iOS apps using UIWebView Control, which can be referred to with the help of this Blog post. [NOTE: This is purely as a reference and is not directly an Android implementation.]




回答2:


You can procure the SWF and JS files from FusionCharts XT pack. Trial download is available from http://www.fusioncharts.com/downloads. You will get these files from Download Pack > Charts folder.

Generally, you need to put these files in the /assets folder. These files get packed with the apk. You can access the files using the path - /assets/....

Reference: Load file from resource

Please remember that in case you are targeting Android v3+, you do not need to render Flash charts. Thus, you do not need to copy these SWF files. FusionCharts offers JavaScript (no Flash) charts, and your implementation gets simpler as detailed in the steps below:

  1. Copy FusionCharts.js, FusionCharts.HC.js, FusionCharts.HC.Charts.js and jquery.min.js to required folder.

However, include only FusionCharts.js in your HTML code. The other JavaScript files will be loaded automatically.

  1. Instead of passing the name of the SWF file, pass the JavaScript alias of the chart. Required modification in your code:

    var myChart = new FusionCharts( \"Column3D\",\"myChartId\...
    

    Column3D is the alias of the chart you are trying to render. No need to prefix it with a path.

  2. DO NOT load XML using setXMLUrl. FusionCharts uses ajax to load the XML data. Local Ajax is not supported (due to the security restrictions) in most of the browsers and it may fail. Instead, load the XML using Android's resource loading mechanism (Load file from resource) and pass the data as String to the chart using setXMLData method.

    myChart.setXMLData(XMLLoadedAsString);
    

MORE: A more synced way is to implement this is to wrap the chart rendering JavaScript code inside FusionCharts's ready Event Listener as shown below:

    <script type=\"text/javascript\">"+

    " FusionCharts.addEventListener(\"ready\", function () { \n"+

    "     var myChart = new FusionCharts( \"FusionCharts/Column3D.swf\",\"myChartId\", \"400\",\"300\", \"0\", \"1\" );"+
    "    myChart.setXMLUrl(\"Data.xml\");"+
    "    myChart.render(\"chartContainer\");"+      

    "\n});"+
    "</script>"


来源:https://stackoverflow.com/questions/13508390/integrate-fusionchart-in-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!