Skip to main content

Bar Chart in MVC Architecture Using phonegap Android

Step 1 . Create Sencha Touch Application
                       Sencha app generate

Step 2 . Adding phonegap plugins

Step 3.


View Page 


BarChart.js


Ext.define('myios.view.BarChart', {
    extend: 'Ext.chart.CartesianChart',
    alias: 'widget.categorybarchart',

    xtype: 'categorybarchart',

    requires: [
        'Ext.chart.series.Bar',
        'Ext.chart.axis.Numeric',
        'Ext.chart.axis.Category',
        'Ext.chart.CartesianChart'
    ],

    config: {

        layout: {
            type: "fit"
        },

        xtype: "chart",
        width: '100%',
        height: '100%',
        store: 'Categories',
        flipXY: true,
        animate: true,
        shadow: true,

        legend: {
            docked: Ext.os.is.Phone ? 'bottom' : 'right' //Phone based legends
        },
interactions: ['itemhighlight'], // Highligting the elements
        axes: [{
           type: 'numeric',
            position: 'bottom',
            fields: ['price', 'balance'],

            title: {
                text: 'Expense Amount',
                fontSize: 20,
                fontWeight: 'bold'
            },

            grid: true,
            minimum: 0,
        }, {

            type: 'category',
            position: 'left',
            fields: ['name'],

            title: {
                text: 'Categories',
                fontSize: 20,
                fontWeight: 'bold'
            },

            label: {
                rotate: {
                    degrees: 315
                }
            }
        }],

        series: [{
            type: 'bar',
            axis: 'bottom',
highlight: true,
 highlightCfg: {
                fillStyle: '#FF0000'
               , strokeStyle: 'black',
                shadowColor: 'black',
               shadowBlur: 8,
                shadowOffsetX: 4,
                shadowOffsetY: 4
            },
            xField: 'name',
            yField: ['price', 'balance'],

            subStyle: {
                fill: ['blue', 'red']
            },

            style: {
                maxBarWidth: 20
            },

            interactions: [{
                type: 'togglestacked',
                gesture: 'doubletap'
            }],

            label: {
                field: ['price', 'balance'],
                display: 'insideEnd'
            }
        }]
    }
});


Store Page

Categories.js

Ext.define('myios.store.Categories', {
    extend: 'Ext.data.Store',
    alias: 'store.categories',

    requires: [
        'myios.model.Category',
        'Ext.data.proxy.LocalStorage'
    ],

    config: {

        autoLoad: true,
        model: 'myios.model.Category',
        storeId: 'Categories',

        proxy: {
            type: 'localstorage',
            id: 'categoryLocalStorage'
        },
 fields: ['name', 'price','balance'],
 data: [
 {'name': 'T','price':500,'balance':475}


 ]
    }
});


Model Page

Category.js

Ext.define('myios.model.Category', {
    extend: 'Ext.data.Model',
    alias: 'model.category',

    requires: [
        'Ext.data.Field',
        'Ext.data.identifier.Uuid'
    ],

    config: {

        identifier: {
            type: 'uuid'
        },

        fields: [
            {
                name: 'id',
                type: 'string'
            },
            {
                name: 'name',
                type: 'string'
            },
            {
               defaultValue: 0.00,
                name: 'price',
                type: 'float'
            },
            {
                defaultValue: 0.00,
                name: 'balance',
                type: 'float'
            }
        ]
    }
});


app.js

Ext.application({
    name: 'myios',

    requires: [
        'Ext.MessageBox'
    ],

    views: [
      'Main','BarChart'
    ],
stores:[
'ChartStore','Categories'
],
    icon: {
        '57': 'resources/icons/Icon.png',
        '72': 'resources/icons/Icon~ipad.png',
        '114': 'resources/icons/Icon@2x.png',
        '144': 'resources/icons/Icon~ipad@2x.png'
    },

    isIconPrecomposed: true,

    startupImage: {
        '320x460': 'resources/startup/320x460.jpg',
        '640x920': 'resources/startup/640x920.png',
        '768x1004': 'resources/startup/768x1004.png',
        '748x1024': 'resources/startup/748x1024.png',
        '1536x2008': 'resources/startup/1536x2008.png',
        '1496x2048': 'resources/startup/1496x2048.png'
    },

    launch: function() {
        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();

        // Initialize the main view
        Ext.Viewport.add(Ext.create('myios.view.CategoryBarChart'));

    },

    onUpdated: function() {
        Ext.Msg.confirm(
            "Application Update",
            "This application has just successfully been updated to the latest version. Reload now?",
            function(buttonId) {
                if (buttonId === 'yes') {
                    window.location.reload();
                }
            }
        );
    }
});








/*
SOME CASE Chart Animation Requires Class Files

Such Case Add Necessary js Files from touch Folder to your project resource folder and map it in app.json file

*/

Comments

Popular posts from this blog

Bluetooth Chat Example

Manifest File <manifest xmlns:android="http://schemas.android.com/apk/res/android"       package="com.example.android.BluetoothChat"       android:versionCode="1"       android:versionName="1.0">     <uses-sdk minSdkVersion="7" />     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />     <uses-permission android:name="android.permission.BLUETOOTH" />     <application android:label="@string/app_name"                  android:icon="@drawable/app_icon" >         <activity android:name=".BluetoothChat"                   android:label="@string/app_name"                   android:configChanges="orientation|keyboardHidden">             <intent-filter> ...

Custom TextView With Images in Android

Create a custom XML Tag with image and text 1) Class extends Textview import java . util . regex . Matcher ; import java . util . regex . Pattern ; import android . content . Context ; import android . text . Spannable ; import android . text . style . ImageSpan ; import android . util . AttributeSet ; import android . util . Log ; import android . widget . TextView ; public class TextViewWithImages extends TextView { public TextViewWithImages ( Context context , AttributeSet attrs , int defStyle ) { super ( context , attrs , defStyle ); } public TextViewWithImages ( Context context , AttributeSet attrs ) { super ( context , attrs ); } public TextViewWithImages ( Context context ) { super ( context ); } @Override public void setText ( CharSequence text , BufferType type ) { Spannable s = getTextWithImages ( getContext (), text ); super . setText...

AcceleroMeter Sensors with SurfaceMovements on Canvas

MainActivity.java import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; public class MainActivity extends Activity implements SensorEventListener { float x, y, sensorX, sensorY; Bitmap ball; SensorManager sm; Sensor s; MyBringBackSurface ourSurfaceView; /**  * Canvas Movement  */ public class MyBringBackSurface extends SurfaceView implements Runnable {     SurfaceHolder ourHolder;     Thread ourThread = null;     boolean isRunning = false;     public MyBringBackSurface(Context context) {         super(context)...