Apr 05, 2014, 4:16 AM
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
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;
}