Hi,
I am implementing a horizontal bar chart drawing out how many times different links are clicked.
The problem is that the labels are not aligned properly. They show up in 2 or 3 columns and alternate between them.
Let say I have bars with equal length and it shows up as such:
bar 2
bar 2
bar 2
bar 2
I have tried setting labelLocation to inside or outside and other settings as well but it did not work.
Another problem is that I want to set the yAxis steps(now horizontal) to integer values because it does not make sense to have decimal places. How do I adjust the steps to jump by exactly 1 instead of 0.2 without specifying the maxvalues, min values etc because I do not know these values. I tried setting LabelSteps to 5 but it only solves the problem for this chart. Is there a better way to do it?
Any help will be greatly appreciated.
My entire code is as such:
namespace TelerikTest |
{ |
public partial class _Default : System.Web.UI.Page |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
//Chart Appearance |
chartControl.PlotArea.Appearance.Border.Visible = false; |
chartControl.IntelligentLabelsEnabled = true; |
chartControl.AutoTextWrap = true; |
chartControl.AutoLayout = true; |
chartControl.SeriesOrientation = Telerik.Charting.ChartSeriesOrientation.Horizontal; |
//Telerik bug: AutoScale will change xAxis Item label to 1.2.3.4.5.... |
chartControl.PlotArea.XAxis.AutoScale = false; |
chartControl.Width = 800; |
chartControl.Legend.Visible = false; |
//chartControl.Legend.Appearance.Position.Auto = false; |
chartControl.PlotArea.Appearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Top; |
Dictionary<string,int> items = new Dictionary<string,int>(); |
items.Add("First",1); |
items.Add("Second",2); |
for (int i = 0; i < 40; i++) |
{ |
items.Add("http://testing1testing2testing3testing4.com" + i, 1); |
int height = (int)chartControl.Height.Value; |
chartControl.Height = height + 15; |
} |
loadBar("",items); |
} |
protected void loadBar(string seriesName, Dictionary<string,int> segments) |
{ |
ChartSeries s = new ChartSeries(seriesName, ChartSeriesType.Bar); |
int c = 0; |
foreach (string segmentName in segments.Keys) |
{ |
int segmentValue = segments[segmentName]; |
s.AddItem(segmentValue); |
s.Items[c].Name = segmentName; |
c++; |
} |
s.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels; |
s.DefaultLabelValue = "#Y"; |
s.Appearance.LabelAppearance.Position.Auto = false; |
s.Appearance.LabelAppearance.LabelLocation = Telerik.Charting.Styles.StyleSeriesItemLabel.ItemLabelLocation.Auto; |
loadRadChart("chartTitle", s); |
} |
public void loadRadChart(string chartTitle, ChartSeries chartSeries) |
{ |
chartControl.Clear(); |
chartControl.PlotArea.XAxis.Clear(); |
chartControl.ChartTitle.TextBlock.Text = chartTitle; |
chartControl.Series.Add(chartSeries); |
foreach (ChartSeriesItem item in chartSeries.Items) |
{ |
if (item.YValue == 0.0) { item.Label.Visible = false; } |
chartControl.PlotArea.XAxis.AddItem(item.Name); |
} |
chartControl.PlotArea.YAxis.LabelStep = 5; |
} |
} |
} |