Click here to Skip to main content
Sign Up to vote bad
good
Hi All,
 
I am trying to create a very simple visual web part in VS2010. Initially the chart control wasnt visible in the toolbox so I had to right click/Choose Items and selected System.Web.UI.DataVisualisation.Charting.
 
The chart control then became visible. I dragged the chart control onto the canvas and I get the following error:
 
Error Creating Control - Chart1
Object Reference not set to an instance of an object when
 
The ascx file looks like this:
 
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="VisualWebPartProject2.VisualWebPart1.VisualWebPart1UserControl" %>
<%@ Register Assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<asp:Chart ID="Chart1" runat="server">
    <Series>
        <asp:Series Name="Series1">
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>
 

Any ideas as to why I'm getting this error and what I can do to rectify the problem?
 
Thanks in advance.
 
Rashed
Posted 4 May '12 - 3:00


2 solutions

Object Reference not set to an instance of an object
This error happens when you try to use a property of an object that is null.
 
You have not defined charts properly. This is not the way chart control is used. Few properties are still to be defined. Look here on how chart control works:
MSDN: Chart Controls[^]
MSDN: Adding a Chart Control[^]
  Permalink  
@sandeep.
 
Thanks for your reply, however the links you sent me were for an asp.net app, when you add the chart control to a webpart the properties mentioned in the link are not available! The error I get is not at build/compile time, the message is over the control on the canvas itself. It seems as though the charts control is not intended to be used in a webpart.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 243
1 Rohan Leuva 220
2 Sergey Alexandrovich Kryukov 208
3 Abhinav S 168
4 Mahesh Bailwal 165
0 Sergey Alexandrovich Kryukov 8,494
1 OriginalGriff 6,799
2 CPallini 3,603
3 Rohan Leuva 2,923
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 5 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid