PDA

View Full Version : [CLOSED] Create a Chart in Code Behind



elisa
Jul 18, 2013, 9:04 PM
I'm trying to create a pie chart in code behind as follows:


Ext.Net.Chart pieChart = new Ext.Net.Chart()
{
Animate = true,
Shadow = true,
InsetPadding = 20,
Theme = "Base:gradients",
LegendConfig =
{
Position = Ext.Net.LegendPosition.Right,
LabelFont = "10px Arial"
},
Store = { GetStorePieChart("GRAPH", osPlatform) },
Series =
{
new Ext.Net.PieSeries() {
AngleField = "TOTAL",
ShowInLegend = true,
Donut = 35,
Highlight = true,
HighlightSegmentMargin = 20,
Label =
{
Field = new string[] {"OSI_PATCH_RATING"},
Display = Ext.Net.SeriesLabelDisplay.Rotate,
Contrast = true,
Font = "10px Arial"
}
}
}
};


But I get this error:


Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 358: };
Line 359:
Line 360: Ext.Net.Chart pieChart = new Ext.Net.Chart()
Line 361: {
Line 362: Animate = true,


I have no problem creating grid panels, containers, etc in a similar way so I don't get why I can't do it with a Chart.

Baidaly
Jul 19, 2013, 12:37 AM
Hello!

You should do it in this way:



Ext.Net.Chart pieChart = new Ext.Net.Chart()
{
Animate = true,
Shadow = true,
InsetPadding = 20,
Theme = "Base:gradients",
LegendConfig = new ChartLegend
{
Position = Ext.Net.LegendPosition.Right,
LabelFont = "10px Arial"
}
};

pieChart.Store.Add(GetStorePieChart("GRAPH", osPlatform));

pieChart.Series.Add(new Ext.Net.PieSeries() {
AngleField = "TOTAL",
ShowInLegend = true,
Donut = 35,
Highlight = true,
HighlightSegmentMargin = 20,
Label = new SeriesLabel {
Field = new string[] {"OSI_PATCH_RATING"},
Display = Ext.Net.SeriesLabelDisplay.Rotate,
Contrast = true,
Font = "10px Arial"
}
});