Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am new to Visual Studio 2012 charts and before asking this question, I researched extensively for the solution to this problem, it has worked for others but not for me. I am trying to add data points to a point chart with the date on the X-Axis (1.08.2013-31.08.2013) and numbers on Y-Axis (1-10). This is the code for my .ascx file with the chart controls:

<asp:Chart ID="ActionsChart1" runat="server" Width="997px">
    <series>
        <asp:Series ChartType="Point" Name="ActionsSeries" XValueType="Date" YValueType="Int32" YAxisType="Primary" XAxisType="Primary">
        
    </series>
    <chartareas>
        <asp:ChartArea Name="ActionPlotArea" AlignmentOrientation="Horizontal">

            <axisy title="Priority" maximum="10" minimum="1" interval="1">
                <majorgrid enabled="False" />
            </axisy>
            <axisx interval="1" intervaloffset="1" intervaloffsettype="Days" intervaltype="Days" islabelautofit="False" maximum="31" minimum="1" title="Date">
                <majorgrid enabled="False" />
                <LabelStyle Angle="-50" Format="dd.08.2013" Interval="1" IntervalOffset="1" IntervalOffsetType="Days" IntervalType="Days" />
            </axisx>

        
    </chartareas>


Here is the class with the function (.ascx.cs) to load data points:

using System;
using System.ComponentModel;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls.WebParts;

namespace ProjectGatewayKeyStats.ActionsChart
{
    [ToolboxItemAttribute(false)]
    public partial class ActionsChart : WebPart
    {
        // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
        // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
        // for production. Because the SecurityPermission attribute bypasses the security check for callers of
        // your constructor, it's not recommended for production purposes.
        // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]

        DataTable actionsTableData = new DataTable();

        public ActionsChart()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void ActionsChart1_Load(object sender, EventArgs e)
        {
            //DOES NOTHING, WHY?
            ActionsChart1.Series["ActionsSeries"].Points.AddXY(new DateTime(2013, 08, 01), 1);
            ActionsChart1.Series["ActionsSeries"].Points.AddXY(new DateTime(2013, 08, 29), 3);
            ActionsChart1.Series["ActionsSeries"].Points.AddXY(new DateTime(2013, 08, 18), 4);
            ActionsChart1.Series["ActionsSeries"].Points.AddXY(new DateTime(2013, 08, 15), 6);
            ActionsChart1.Series["ActionsSeries"].Points.AddXY(new DateTime(2013, 08, 24), 2);
            ActionsChart1.Series["ActionsSeries"].Points.AddXY(new DateTime(2013, 08, 28), 5);
        }
    }
}

The result of the above code is just a blank chart with no points on it. Do I need to set a marker.Visible or something? Please help. Thanks.
Posted
Updated 16-Aug-13 5:58am
v2
Comments
Ron Beyer 16-Aug-13 12:49pm    
Did you set a breakpoint at the last insert and make sure that the data was making it into the points array, or that the function was being called at all? Sometimes I've seen VS disconnect events, make sure that the event is still connected so that the load function is called.
Member 10213905 20-Aug-13 4:13am    
The webpart for the chart is not getting added now.. The error message is that it has been removed from the gallery. Do you know what could cause this?

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