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" >
<Series>
<rad:ChartSeries Type ="Gantt" DataYColumn="EndDate" DataYColumn2="StartDate" DataXColumn ="ResourceId" DefaultLabelValue = "#Y" >
<Appearance>
<LabelAppearance Visible="false" />
</Appearance>
</rad:ChartSeries>
</Series>
<PlotArea>
<YAxis>
<AxisLabel>
<Appearance RotationAngle="360">
</Appearance>
</AxisLabel>
</YAxis>
</PlotArea>
<ChartTitle>
<Appearance Dimensions-Margins="1%, 1%, 1%, 1%" Position-AlignedPosition="Top">
</Appearance>
<TextBlock Text="ADS Resource Chart">
</TextBlock>
</ChartTitle>
<Legend Appearance-ItemAppearance-Visible ="false" >
<Items>
</Items>
<TextBlock></TextBlock>
</Legend>
</rad:RadChart>
</asp:Content>
---------------------------------------------------------------------------------------------
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.DataBind();
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();
RadChart1.Legend.Items.Add(lbi);
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()))
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];
}
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
-Dhamu