[CLOSED] charts from code behind not showing via OnDirectClick method

  1. #1

    [CLOSED] charts from code behind not showing via OnDirectClick method

    I tried to load the chart from Page_Load with below code and it works,
    and then I add a Button in the aspx file, and use OnDirectClick="LoadSimpleChart", but the chart didn't show up.

     protected void Page_Load(object sender, EventArgs e)
            {
                //this.LoadSimpleChart();
            }
    <ext:Button ID="Button21" runat="server" Text="Load Chart" AutoDataBind="true"
      Icon="Zoom" ToolTip="<%# @Resources.AmsResource.BUTTON_SEARCH %>" OnDirectClick="LoadSimpleChart" >
    </ext:Button>
            public void LoadSimpleChart()
            {    // create sample data
                System.Data.DataTable dt = new System.Data.DataTable();
                Random ran = new Random();
    
                System.Data.DataColumn dc = new System.Data.DataColumn("Name");
                dc.DataType = System.Type.GetType("System.String");
                dt.Columns.Add(dc);
                dc = new System.Data.DataColumn("Data");
                dc.DataType = System.Type.GetType("System.Int32");
                dt.Columns.Add(dc);
                System.Data.DataRow dr = dt.NewRow();
                dr[0] = "January";
                dr[1] = ran.Next(0, 100);
                dt.Rows.Add(dr); dr = dt.NewRow();
                dr[0] = "February";
                dr[1] = ran.Next(0, 100);
                dt.Rows.Add(dr); dr = dt.NewRow();
                dr[0] = "March is just way too long for this";
                dr[1] = ran.Next(0, 100);
                dt.Rows.Add(dr);
    
    
                //if (!X.IsAjaxRequest)
                //{
                    Ext.Net.Panel pnl = new Ext.Net.Panel
                    {
                        Title = "Chart Test",
                        Layout = "FitLayout",
                        Width = 300,
                        Height = 500,
                        Items =
                    {
                        new Chart {
                             ID = "ChartTest",
                             Shadow = true,
                             Animate = true,
                             //LegendConfig = { Position = LegendPosition.Top },
                             LegendConfig = new ChartLegend() { Position = LegendPosition.Top },
                             Store = {
                                new Store {
                                    DataSource = dt,
                                     AutoDataBind = true,
                                     Model = {
                                        new Model {
                                            Fields = {
                                                new ModelField { Name = "Name" },
                                                new ModelField { Name = "Data" }
                                            }   
                                        }   
                                     }  
                                }
                             },
                             Axes = {
                                new NumericAxis { Fields = new string[] { "Data" }, Title = "Number", Minimum = 0 },
                                new CategoryAxis { Position = Position.Bottom, Fields = new string[] { "Name" }, Title = "Name" }
                             },
                             Series = {
                                new ColumnSeries { Axis = Position.Left, XField = new string[] { "Name" }, YField = new string[] { "Data" } }   
                             }
                        }
                    }
                    };
    
                    this._extFP.Controls.Add(pnl);
                    this._extFP.Reload();
                //}
    
            }
    Best Regards,
    Paggy
    Last edited by Daniil; Jan 17, 2014 at 11:19 AM. Reason: [CLOSED]
  2. #2
    Hi @Paggy,

    Please replace
    this._extFP.Controls.Add(pnl);
    this._extFP.Reload();
    with
    this._extFP.Items.Add(pnl);
    pnl.Render();
    Here you can find some examples how to render stuff in DirectEvents and DirectMethods.
    https://examples2.ext.net/#/search/xrender
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @Paggy,

    Please replace
    this._extFP.Controls.Add(pnl);
    this._extFP.Reload();
    with
    this._extFP.Items.Add(pnl);
    pnl.Render();
    Here you can find some examples how to render stuff in DirectEvents and DirectMethods.
    https://examples2.ext.net/#/search/xrender

    Thanks Daniil, it works. ;-)

    Best Regards,
    Paggy

Similar Threads

  1. [CLOSED] charts from code behind not showing
    By tMp in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Jan 17, 2014, 4:15 AM
  2. [CLOSED] Charts created in code behind
    By cwolcott in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 31, 2012, 5:35 PM
  3. [CLOSED] I need to create charts from code behind, but how to?
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 06, 2012, 11:29 AM
  4. New Tab not showing up.... (code behind)
    By meareal in forum 1.x Help
    Replies: 5
    Last Post: Jan 05, 2011, 6:49 PM
  5. Replies: 1
    Last Post: Jul 01, 2009, 3:14 PM

Posting Permissions