A.Vila
A.Vila

Reputation: 1496

How to include Dojo charting in titanium project

I'm trying to include Dojo charts in a titanium project.

I've tried to load a webview with Dojo declarations and then load the webview in the app. But I can't make it working. I've included in my project a folder (libs_dojo) with:

This is the simple html I'm using:

<html>
<head>
    <title>Chart</title>
</head>
<body>
    <div id="simplechart" style="width: 250px; height: 150px;"></div>
    <script src='libs_dojo/dojo.js' data-dojo-config="async:true"></script>
    <script>
        require([
            "libs_dojo/dojox/charting/Chart",
            "libs_dojo/dojox/charting/plot2d/Lines",
            "libs_dojo/dojox/charting/axis2d/Default",
            "libs_dojo/domReady!"
            ],
                function (Chart) {
                    var chart = new Chart("simplechart");
                    chart.addPlot("default", {type: "Lines"});
                    chart.addAxis("x");
                    chart.addAxis("y", {vertical: true});
                    chart.addSeries("Series 1", [1, 2, 2, 3, 4, 5, 5, 7]);
                    chart.render();
                });
    </script>
</body>
</html>

When I tried it, I found a lot of "Error loading xxx/libs_dojo/_base/lang.js or libs_dojo/_base/array.js..."

How does dojo require work? Can I do it otherwise? programmatically? Do you know what the problem could be?

Thanks in advance!

Upvotes: 1

Views: 176

Answers (2)

Bharadwaj
Bharadwaj

Reputation: 1351

You should not pick and choose JS files from dojo package the way you seem to be doing. Either go with Miriam's approach of linking through web (googleapi) or place the whole dojo directory in your lib and reference dojo.js before anything else (that is require statements). You may want to read the example in CDN usage section of Hello Dojo

Every JS in dojo has dependent JS - which it fetches asnchronously (you might want to read up about dojo's AMD). The error that you see is because of some of the dependent JS not being found.

Upvotes: 1

MiBrock
MiBrock

Reputation: 1100

This might be helpful: http://dojotoolkit.org/reference-guide/1.8/dojox/charting.html?highlight=charts and http://dojotoolkit.org/documentation/tutorials/1.9/charting/

The second one is a very good Tutorial.

Make sure you have load all scripts needed to run dojo. Have you downloaded the dojo.js? Otherwise you must load it like this :

src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js">

Here's an Example from dojo :

require([
 // Require the basic 2d chart resource
"dojox/charting/Chart",

// Require the theme of our choosing
"dojox/charting/themes/Claro",

], function(Chart, theme){
    // ....
});

Regards, Miriam

Upvotes: 1

Related Questions