Rad chart X axis Label Issue

Thread is closed for posting
2 posts, 0 answers
  1. Dhamodharan
    Dhamodharan avatar
    1 posts
    Member since:
    May 2011

    Posted 12 Jul 2011 Link to this post


    Here with I attached my project code and chart.

    The problem is If I remove the lable code the chart is working fine but ,
    If I add label code on cs file my chart is not coming up.

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ResourceChart.aspx.cs" Inherits="ResourceChart" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="rad" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Charting" TagPrefix="rad" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <rad:RadChart ID ="RadChart1" runat="server" Height="750px" Width ="1700px" UseSession ="false"  >
        <rad:ChartSeries Type ="Gantt" DataYColumn="EndDate" DataYColumn2="StartDate" DataXColumn ="ResourceId" DefaultLabelValue = "#Y" >
               <LabelAppearance  Visible="false" />


                    <Appearance RotationAngle="360">

            <Appearance Dimensions-Margins="1%, 1%, 1%, 1%" Position-AlignedPosition="Top">
            <TextBlock Text="ADS Resource Chart">
        <Legend Appearance-ItemAppearance-Visible ="false"  >






    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Data;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using NOVADS_Tracker;
    using Telerik.Charting;
    using System.Web.UI.HtmlControls;
    using System.ComponentModel;
    using System.Collections;
    using DHAdmin;

    public partial class ResourceChart : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)

            DataSet ds = ResourceList.ResourceChart_Data();

            this.RadChart1.DataSource = ds;

            this.RadChart1.PlotArea.YAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate;
            this.RadChart1.PlotArea.YAxis.Appearance.CustomFormat = "dd MMMM";
            this.RadChart1.PlotArea.YAxis.IsZeroBased = false;

            this.RadChart1.SeriesOrientation = Telerik.Charting.ChartSeriesOrientation.Horizontal;

            //this.RadChart1.PlotArea.XAxis.MaxItemsCount = 1;
            this.RadChart1.PlotArea.XAxis.AutoScale = false;

            RadChart1.PlotArea.Appearance.Dimensions.Margins.Top = 100;
            RadChart1.PrePaint += new EventHandler<EventArgs>(RadChart2_PrePaint);



            this.RadChart1.Legend.Appearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Right;
            for (int i = 0; i < RadChart1.Series[0].Items.Count; i++)
                LabelItem lbi = new LabelItem();
                string mileName = ds.Tables[0].Rows[i]["MilestoneName"].ToString();
                string colorHex = ds.Tables[0].Rows[i]["ColorCode"].ToString();

                RadChart1.Legend.Items[i].TextBlock.Text = mileName;
                RadChart1.Legend.Items[i].Marker.Appearance.FillStyle.MainColor = System.Drawing.ColorTranslator.FromHtml(colorHex);
                RadChart1.Legend.Items[i].Marker.Appearance.FillStyle.SecondColor = System.Drawing.ColorTranslator.FromHtml(colorHex);




            for (var i = 0; i < RadChart1.Series[0].Items.Count; i++)
                string colorHex = ds.Tables[0].Rows[i]["ColorCode"].ToString();
                RadChart1.Series[0].Items[i].Appearance.FillStyle.MainColor = System.Drawing.ColorTranslator.FromHtml(colorHex);
                RadChart1.Series[0].Items[i].Appearance.FillStyle.SecondColor = System.Drawing.ColorTranslator.FromHtml(colorHex);




            //for (int i = 0; i < RadChart1.Series[0].Items.Count;i++)
            //    RadChart1.PlotArea.XAxis[i].TextBlock.Text = ds.Tables[0].Rows[i]["ResourceName"].ToString();



            //this.RadChart1.PlotArea.XAxis.AutoScale = false;

            //List<string> lLabel = new List<string>();

            //foreach (DataRow dr in ds.Tables[0].Rows)
            //    if (!lLabel.Contains(dr["ResourceName"].ToString()))
            //        lLabel.Add(dr["ResourceName"].ToString());
            //RadChart1.PlotArea.XAxis.MaxItemsCount = 0;
            //RadChart1.PlotArea.XAxis.AddRange(1, lLabel.Count, 1);

            //for (int i = 0; i < lLabel.Count; i++)
            //    RadChart1.PlotArea.XAxis[i].TextBlock.Text = lLabel[i];



        void RadChart2_PrePaint(object sender, EventArgs e)

            //Double maxVal = RadChart1.PlotArea.XAxis.MaxValue;

            foreach (var item in RadChart1.PlotArea.XAxis.Items)
                float x = item.Appearance.Position.X;
                float y = item.Appearance.Position.Y;

                item.Appearance.Position.Auto = false;

                item.Appearance.Position.Y = y;
                item.Appearance.Position.X = x + 620;
                //item.Appearance.Position.X = x + (float)(maxVal);



    This is the small piece of code trying to get the label on right side.

    Code value everything is correct but final output is not coming up with what I expected.

    List<string> lLabel = new List<string>();

            foreach (DataRow dr in ds.Tables[0].Rows)
                if (!lLabel.Contains(dr["ResourceName"].ToString()))

            RadChart1.PlotArea.XAxis.MaxItemsCount = 0;

            RadChart1.PlotArea.XAxis.AddRange(1, lLabel.Count, 1);

            for (int i = 0; i < lLabel.Count; i++)
                RadChart1.PlotArea.XAxis[i].TextBlock.Text = lLabel[i];

    See attached chart image files I would like to combine the both  means

    Chart1.png one plotting is correct .

    Chart2.png right side name is coming up correctly but chart is not correct like chart1.png.

    I want chart1 chart  with lable like chart2.

    please help how to fix this issue


  2. Yavor
    Yavor avatar
    11 posts

    Posted 15 Jul 2011 Link to this post

    Hello Dhamodharan,

    Based on the supplied information, it is hard to determine what is causing this unwanted behavior. If the problem persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and advise you further.

    Best wishes,
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top