Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

XML
<%@ 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

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[^]
 
Share this answer
 
@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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900