We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Object Reference Not Set When Placing Chart on Form

I received this message when I try to compile. My chart became a box with a red border and a trace message inside ("System.NullReferenceException..."). Somehow or other I managed to get this to run and the chart appeared at run time. Now however the chart appears at design time but my program appears to compile but I get the message Object Reference Not Set when the form tries to load. The Stack Trace starts StackTrace " at Syncfusion.Windows.Forms.Chart.ChartLegend.AutoSize(Rectangle rect) at Syncfusion.Windows.Forms.Chart.ChartLegend.AutoLocation(Rectangle rect) at Syncfusion.Windows.Forms.Chart.ChartControl.RecalculateSizes() at Syncfusion.Windows.Forms.Chart.ChartLegend.OnRecalculateSizes() at Syncfusion.Windows.Forms.Chart.ChartLegend.OnLegentSizeChange() at Syncfusion.Windows.Forms.Chart.ChartLegend.set_CustomItems(LegendItem[] value) This seems to be a legend problem. I''ve re-installed Syncfusion and Studio but still have the problem. I can''t keep replacing the Chart on the form as it is too time consuming.

5 Replies

HG Hamish Gunn August 26, 2005 10:37 AM UTC

The problem appears to be that the Chart Designer is not creating the Legend. The error occurs at the line which Adds a Legend. The parameter is a ChartLegend object: '' ''chrtOutput '' Me.chrtOutput.BackColor = System.Drawing.Color.White Me.chrtOutput.Controls.Add(Me.chrtOutput.Legend) ... - Me.chrtOutput.Legend {Syncfusion.Windows.Forms.Chart.ChartLegend} Syncfusion.Windows.Forms.Chart.ChartLegend + AccessibilityObject {System.Windows.Forms.Control.ControlAccessibleObject} System.Windows.Forms.AccessibleObject AccessibleDefaultActionDescription Nothing String AccessibleDescription Nothing String AccessibleName Nothing String AccessibleRole Default System.Windows.Forms.AccessibleRole AllowDrop False Boolean Anchor 9 System.Windows.Forms.AnchorStyles + BackColor {System.Drawing.Color} System.Drawing.Color BackgroundImage Nothing System.Drawing.Image BindingContext Nothing System.Windows.Forms.BindingContext + Border {Syncfusion.Windows.Forms.Chart.LineInfo} Syncfusion.Windows.Forms.Chart.LineInfo Bottom 48 Integer + Bounds {System.Drawing.Rectangle} System.Drawing.Rectangle CanFocus False Boolean CanSelect True Boolean Capture False Boolean CausesValidation True Boolean + ClientRectangle {System.Drawing.Rectangle} System.Drawing.Rectangle + ClientSize {System.Drawing.Size} System.Drawing.Size Columns 1 Integer CompanyName "Syncfusion, Inc." String Container Nothing System.ComponentModel.IContainer ContainsFocus False Boolean ContextMenu Nothing System.Windows.Forms.ContextMenu + Controls {System.Windows.Forms.Control.ControlCollection} System.Windows.Forms.Control.ControlCollection Created True Boolean + Cursor {System.Windows.Forms.Cursor} System.Windows.Forms.Cursor CustomItems {Length=0} Syncfusion.Windows.Forms.Chart.LegendItem() + DataBindings {System.Windows.Forms.ControlBindingsCollection} System.Windows.Forms.ControlBindingsCollection + DefaultBackColor {System.Drawing.Color} System.Drawing.Color + DefaultFont {System.Drawing.Font} System.Drawing.Font + DefaultForeColor {System.Drawing.Color} System.Drawing.Color + DisplayRectangle {System.Drawing.Rectangle} System.Drawing.Rectangle Disposing False Boolean Dock None System.Windows.Forms.DockStyle Enabled True Boolean FloatingAutoSize True Boolean Focused False Boolean + Font {System.Drawing.Font} System.Drawing.Font + ForeColor {System.Drawing.Color} System.Drawing.Color Handle 2035040 System.IntPtr HasChildren False Boolean Height 28 Integer ImeMode NoControl System.Windows.Forms.ImeMode InvokeRequired False Boolean IsAccessible False Boolean IsDisposed False Boolean IsHandleCreated True Boolean ItemsAlignment Near System.Drawing.StringAlignment Left 162 Integer LegendAlignment Center System.Drawing.StringAlignment + Location {System.Drawing.Point} System.Drawing.Point ModifierKeys None System.Windows.Forms.Keys MouseButtons None System.Windows.Forms.MouseButtons + MousePosition {System.Drawing.Point} System.Drawing.Point Name "" String Orientation Horizontal System.Windows.Forms.Orientation + Parent {Syncfusion.Windows.Forms.Chart.ChartControl} System.Windows.Forms.Control Position Top Syncfusion.Windows.Forms.Chart.ChartLegendPosition ProductName "Essential Chart" String ProductVersion "3.201.1.0" String RecreatingHandle False Boolean Region Nothing System.Drawing.Region RepresentationType SeriesType Syncfusion.Windows.Forms.Chart.ChartLegendRepresentationType Right 238 Integer RightToLeft No System.Windows.Forms.RightToLeft Rows 1 Integer ShowBorder True Boolean ShowSymbol False Boolean Site Nothing System.ComponentModel.ISite + Size {System.Drawing.Size} System.Drawing.Size Spacing 4 Integer TabIndex 3 Integer TabStop True Boolean Tag Nothing Object Text "" String Top 20 Integer TopLevelControl Nothing System.Windows.Forms.Control Visible True Boolean Width 76 Integer + WindowTarget {System.Windows.Forms.Control.ControlNativeWindow} System.Windows.Forms.IWindowTarget


HG Hamish Gunn August 26, 2005 11:23 AM UTC

The legend customitems had an item of nothing. I removed this from the code and I appear to be back working.


AD Administrator Syncfusion Team August 26, 2005 03:51 PM UTC

Hi, Thanks for the feedback. We are currently working on optimizing the initial code that is serialized when the ChartControl is added to the form. The legend should not be created explicitly and added to the chartcontrol - it should be internal. We should have these changes done within the next few weeks. Thanks, Davis


HG Hamish Gunn August 31, 2005 08:30 AM UTC

I have set up a DirectTrac incident. I am not manually creating a Legend, it is the designer. It generates a line of code: Me.chrtOutput.Legend.CustomItems = New Syncfusion.Windows.Forms.Chart.LegendItem() {Nothing} which appears to be the problem. I comment it out and things seem to work. Thanks


AD Administrator Syncfusion Team August 31, 2005 01:42 PM UTC

Hi, Sorry I wasn''t clear. I was just commenting that the code generation for the ChartControl should keep the legend internal. Regards, Davis

Loader.
Live Chat Icon For mobile
Up arrow icon