English 中文(简体)
Could not able to render simple Piechart using ExtJs 3.0
原标题:

I was trying to render a simple piechart using ExtJs 3.0 but could not. Below is the snippet:

<div id="ext_grid_panel">

    <div id="blackout_tab">
        <div id="grid_blackout_current"></div>
    </div>

    <div id="gls_tab">
         <div id="gls_current"></div>
    </div>

</div>

var mainGridPanelWidth = (Ext.IsIE)?  : width:  100% , ;
var mainGridPanel = new Ext.TabPanel({
    id:  maingridpanel ,
    renderTo:  ext_grid_panel ,
    style: {width: 100% },
    tabWidth: 1000,
    activeTab: 0,
    items: [
        {id:  allTabPanel ,contentEl:  blackout_tab ,title:  All },
        {id:  glsTabPanel ,contentEl:  gls_tab ,title:  GLS }

    ]
});

if (!Ext.IsIE)
    mainGridPanel.setWidth( 100% );

Ext.getCmp( allTabPanel ).on( activate , function() {

}); 

Ext.getCmp( glsTabPanel ).on( activate , function() {   

}); 


var pieChart = {
        xtype :  piechart ,
        store : [{ total  : 42 ,  range : 20,000 },{ total  : 53 ,  range : 10,000 }],
        dataField :  total ,
        categoryField :  range          
        };

var panelBlackoutCurrent = new Ext.Panel({
    id:  panelblackoutcurrent ,
    renderTo:  grid_blackout_current ,
    items: [
            pieChart
    ]
});

var panelglsCurrent = new Ext.Panel({
    id:  panelglscurrent ,
    renderTo:  gls_current ,
    items: [
        pieChart
    ]
});

When i inspect in firefox firebug, i see an object(.swf) is created but the piechart content is not there/rendered.

Quick guidance is highly appreciated as it is taking lot of time with no solution

最佳回答
问题回答

here come my version

<html>
<head>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<!-- GC -->
    <!-- LIBS -->
    <script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
    <!-- ENDLIBS -->

    <script type="text/javascript" src="../../ext-all.js"></script>



    <!-- Common Styles for the examples -->
    <link rel="stylesheet" type="text/css" href="../shared/examples.css" />
</head>
<body>

<div id="ext_grid_panel">

</div>
<script>
Ext.onReady(function(){
    var store = new Ext.data.JsonStore({
        fields: [ total ,  range ],
        autoLoad: true,
        data: [
            {
                total: 42,
                range: 20,000 
            }
            ,{
                total: 53,
                range: 10,000 
            }
        ]
    });


    var mainGridPanel = new Ext.TabPanel({
        renderTo:  ext_grid_panel ,
        //style: {width: 100% },
        width:  100% ,
        height: 400,
        activeTab: 0,

        plain: true,
        items: [
            {
                id:  panelglscurrent ,
                title:  GPS ,
                layout:  fit ,
                listeners: {
                    activate: function(){
                    }
                },
                items: [{
                    id:  chart1 ,
                    xtype :  piechart ,
                    store : store,
                    dataField :  total ,
                    categoryField :  range                  
                }]
            },
            {
                id:  panelblackoutcurrent ,
                title:  All ,
                layout:  fit ,
                listeners: {
                    activate: function(){

                    }
                },
                items: [
                   {
                    id:  chart2 ,
                    xtype :  piechart ,
                    store : store,
                    dataField :  total ,
                    categoryField :  range                  
                   }
                ]
            }
        ]
    });

    Ext.getCmp( panelglscurrent ).on( activate , function() {
        Ext.getCmp( panelglscurrent ).doLayout(true);
    }); 

    Ext.getCmp( panelblackoutcurrent ).on( activate , function() {   
        Ext.getCmp( panelblackoutcurrent ).doLayout(true);
    }); 

    if (!Ext.IsIE)
        mainGridPanel.setWidth( 100% );
});





</script>
</body>

</html>

your sample had a few problems:

  • first you have to create a proper store passing the array of object to the pie chart is not enought
  • also you should wrap your code inside Ext.onReady or you can get some strange behaviour like element not rendering properly
  • make sure to include the plain: true on tabPanel with chart inside or the chart won t render properly

an general note

  • try to give good name at your variable (like mainGridPanel being actually a TabPanel)
  • intent properly your code, by experience it really become messy fast.

Also if you want to make the extjs component using full screen, you have better to use the viewport it would make everything resize nicely and make things more easy for you





相关问题
ExtJS load form items/fields from database

I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don t know witch fields my form will have and I want to generate all formpanel ...

How to use Ext JS for role based application

I am planning to use Ext JS for a large application. The application s features are role based. When user login, they only see menu and screen features related to them. My server side technology will ...

Dynamically adding a TabPanel to a Panel Region

I have a Panel layout with a TreePanel in one region. A user clicks on an node in the tree and a TabPanel should be displayed in another region with information, editing tools etc. for that tree node....

How to embed Json result within Extjs Panel?

I have some issues with Json result and embed it within the html of the Extjs Panel. Here s that I have managed to get so far. myPanel is embedded within a mainPanel, and I have some shows/hide of ...

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have ...

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel ...

Merged Headers in Ext JS Grid

Is it possible to have two headers in Ext JS grids? I have to show my grid as grouped data.. for example product types and products. In my case I need a grid like this: Field | Product Type A ...

热门标签