Object reference not set to an instance of an object. when create dynamic Barchart in code-bind

  1. #1

    Object reference not set to an instance of an object. when create dynamic Barchart in code-bind

    Hi guys..
    I created barchart dinamic. But it's not work.. And when i create dynamic linechart. it's same error.
    Please tell me what is this problem.

    Thanks.

    Here is my code
    public Chart fn_Generate_BarChart(string ID, DataTable dtData)
        {
            Chart barChart = new Chart() { ID = "bar" + ID, Animate = true, Shadow = true, Theme = "CustomBlue" };
            Store st = new Store() { ID = "stbar" + ID, AutoDataBind = true };
            Model md = new Model() { ID = "mdbar" + ID };
            ModelField m1 = new ModelField() { Name = "NAME" };
            ModelField m2 = new ModelField() { Name = "DATA"};
            md.Fields.Add(m1); md.Fields.Add(m2);
            st.Model.Add(md);
            st.DataSource = dtData;
            barChart.Store.Add(st);
            //Error here
            barChart.Axes.Add(new NumericAxis()
            {
                Fields = new string[] { "DATA" },
                Position = Position.Bottom,
                Grid = true,
                Label = { Renderer = { Handler = "return Ext.util.Format.number(value, '0,0');" } }
            });
            barChart.Series.Add(new BarSeries()
            {
                Axis = Position.Bottom,
                Highlight = true,
                XField = new string[] { "NAME" },
                YField = new string[] { "DATA" },
                Tips =
                {
                    TrackMouse = true,
                    Renderer = { Handler = "this.setTitle(storeItem.get('NAME') + ': ' + storeItem.get('DATA'));" }
                },
                Label =
                {
                    Display = SeriesLabelDisplay.InsideEnd,
                    Field = new string[] { "DATA" },
                    Orientation = Orientation.Horizontal,
                    Color = "#333",
                    TextAnchor = "middle"
                }
            });
            return barChart;
        }
    Attached Thumbnails Click image for larger version. 

Name:	errorBarchart.PNG 
Views:	20 
Size:	13.3 KB 
ID:	9461  
  2. #2
    Column chart is also too.
  3. #3
    Hi @dinhhung09138,

    Please provide us with a standalone example which we can copy, paste and run without any changes from our side.

Similar Threads

  1. Replies: 2
    Last Post: Jun 13, 2013, 3:58 PM
  2. Replies: 2
    Last Post: Dec 17, 2012, 3:00 AM
  3. Bind dynamic object in store with readData
    By Yoann in forum 2.x Help
    Replies: 4
    Last Post: Oct 22, 2012, 8:36 AM
  4. Replies: 1
    Last Post: Jun 27, 2012, 9:19 PM
  5. Replies: 0
    Last Post: Jun 03, 2009, 4:18 AM

Posting Permissions