[CLOSED] charts from code behind not showing

  1. #1

    [CLOSED] charts from code behind not showing

    I trying to get to know the new charts a little bit better but already when creating a simple sample chart it doesn't show. What did I do wrong?

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            // 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] = "Jan";
            dr[1] = ran.Next(0, 100);
            dt.Rows.Add(dr); dr = dt.NewRow();
            dr[0] = "Feb";
            dr[1] = ran.Next(0, 100);
            dt.Rows.Add(dr); dr = dt.NewRow();
            dr[0] = "Mar";
            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",
                    Items =
                    {
                        new Chart {
                             ID = "ChartTest",
                             Shadow = true,
                             Animate = true,
                             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.Form.Controls.Add(pnl);
            }
        }
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <div>
        
        </div>
        </form>
    </body>
    </html>
    Thanks for a nudge in the right direction.

    best regards.
    Last edited by Daniil; Jan 17, 2014 at 4:15 AM. Reason: [CLOSED]
  2. #2
    Hi @tMp,

    Just set up some size for the Panel:)
    Width = 400,
    Height = 400,
  3. #3
    Ou, shoot. I automatically assumed that it just take the whole space without hight and width.

    thank you!

    And I found one more ways that the chart is not correctly showing for me:

    Uncomment the LegendConfig and you get this: http://forums.ext.net/showthread.php...in-Code-Behind
    Do I really have to break the construction apart, or is there another way to do it?


    New example.
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <!DOCTYPE html>
     
    <script runat="server">
     
        protected void Page_Load(object sender, EventArgs e)
        {
            // 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 },
                             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.Form.Controls.Add(pnl);
            }
        }
     
    </script>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <div>
         
        </div>
        </form>
    </body>
    </html>
    Last edited by tMp; Jan 16, 2014 at 1:53 PM.
  4. #4
    Quote Originally Posted by tMp View Post
    1) Uncomment the LegendConfig and you get this: http://forums.ext.net/showthread.php...in-Code-Behind
    Do I really have to break the construction apart, or is there another way to do it?
    Please replace
    LegendConfig = { Position = LegendPosition.Top },
    with
    LegendConfig = new ChartLegend() { Position = LegendPosition.Top },
    Quote Originally Posted by tMp View Post
    2) When the Text of the bottom axis is getting to long I either don't see everything or I don't see the text at all. Is there a way how I can confine this text in a box so that it just breaks when it gets too long?

    PS: And is there a way that I can force the order of the bars/columns? Like when I have a top (10) select result, it shows me the bars from bottom to top which I would like to change from top to bottom (First record at the top).
    Please start new threads for each issue.
  5. #5
    Quote Originally Posted by Daniil View Post
    Hi @tMp,

    Just set up some size for the Panel:)
    Width = 400,
    Height = 400,
    Hi Daniil,

    It works with Page_Load, but it doesn't work with buttion.OnDirectClick(method), any suggestion?


    Paggy
  6. #6
    Thank you, working perfectly.

    I am changing my post above, so this thread stays clean.
  7. #7
    Quote Originally Posted by tMp View Post
    Thank you, working perfectly.

    I am changing my post above, so this thread stays clean.

    Hi Daniil,

    Should I create another thread for my question?

    I copied above code and put it in Page_Load, it works perfectly, and then I create a function (LoadChart) and put the code there, also add a Button in the aspx file, and use OnDirectClick="LoadChart", but the chart didn't show up.


    Paggy
  8. #8
    Hi @Paggy,

    Yes, please start a new forum thread. If you feel the threads are related, please feel free to cross reference between the two.

Similar Threads

  1. [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
  2. [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
  3. New Tab not showing up.... (code behind)
    By meareal in forum 1.x Help
    Replies: 5
    Last Post: Jan 05, 2011, 6:49 PM
  4. Replies: 2
    Last Post: Jul 01, 2009, 4:49 PM
  5. Replies: 1
    Last Post: Jul 01, 2009, 3:14 PM

Posting Permissions