How to use Charts on mobile is one of those areas where everyone has an opinion. Usually these approaches boil down to the use of a WebView or taking a dependency on a 3rd party native framework.
Usually I recommend using a WebView as the web charting tools tend to provide a greater level of functionality. But recently I discovered JBChartView by Jawbone which changed my mind. JBChartView provides charting functionality I typically use bundled in an easy to use native iOS (sorry not android version) project.
To make JBChartView consumable by Titanium I’ve wrapped the project into a module, Ti.JBChart , and created Titanium specific documentation and examples. The below animated gif shows the Ti.JBChart examples in action.
In Action
An example
The Ti.JBChart github project has examples for Bar, Line, and Area charts. The following snippet shows an example on how to use the LineChartView in your Titanium project.
function createData(){
var result =[];
function createRandom(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
for (var iLoop=0;iLoop<12;iLoop++){
result.push(createRandom(1,12));
}
return result;
}
var data = [];
//Add first line chart
data.push(createData());
//Add second line chart
data.push(createData());
var myStyles = [];
//Create the first line chart with a solid line
myStyles.push(chart.CHART_LINE_SOLID);
//Create the second line chart as a with a dashed line
myStyles.push(chart.CHART_LINE_DASHED);
var lineChart = chart.createLineChartView({
width:Ti.UI.FILL, height:250,
data : data,
toolTipData : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
selectedLineColors :['yellow','orange'],
lineColors:['green','blue'],
styles : myStyles,
selectionBarColor:'purple',
chartBackgroundColor:'#404041'
});
Looking for more?
- Visit the Ti.JBChart project on Github here.
- Read the documentation here.
- Get the example app here.
