Question from Stackoverflow: http://stackoverflow.com/questions/14931894/ultrachart-infragistics
have an asp .net application which uses an infragistics Ultrachart as a Radar chart. Now the chart is like below
Is it possible to add text next to the radians and levels like below? Any examples please?
There are different approaches to solve this task. In attached sample I`m using Composite Radar chart with Annotations and Text primitives (please see both attachments - WinForms application and ASP application for more details)
Q said:"Is it possible to add text next to the radians and levels like below?"
About the labels around the chart, you could use NumericSeries. By this way you could provide string and decimal value. For example:
DataTable dt = new DataTable();
dt.Columns.Add("Label", typeof(string));
dt.Columns.Add("Value", typeof(double));
dt.Rows.Add("My Label 1", 10);
dt.Rows.Add("My Label 2", 20);
NumericSeries series1 = new NumericSeries();
series1.DataBind(dt,"Value", "Label");
series1.PEs.Add(new PaintElement(Color.Red));
myLayer.Series.Add(series1);
this.ultraChart1.CompositeChart.Series.Add(series1);
this.ultraChart1.CompositeChart.ChartLayers.Add(myLayer);
Another option could be if you are using Points collection of you NumericSeries. For example:
for (int k = 0; k < 10; k++)
{
series1.Points.Add( new NumericDataPoint(k + 10, "Label " + k.ToString() + "0", false));
}
About the labels near to Y axis, you could add BoxAnnotation. For example:
private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) { int k = 0; ultraChart1.Annotations.Annotations.Clear(); foreach (Primitive pr in e.SceneGraph) { if (pr.GetType() == typeof(Text) && ((Text)pr).Path == "Border.Title.Grid.Y") { k++; string temp = ((Text)pr).GetTextString(); BoxAnnotation BoxAnn = new BoxAnnotation(); BoxAnn.Location.Type = LocationType.Pixels; BoxAnn.Border.Thickness = 0; BoxAnn.TextStyle.FontColor = Color.DimGray; BoxAnn.Text = temp + " Custom Label " + k.ToString(); BoxAnn.Location.LocationX = ((Text)pr).bounds.X + 70; BoxAnn.Location.LocationY = ((Text)pr).bounds.Y; ultraChart1.Annotations.Add(BoxAnn); } } }
Another option is direct to override your Y axis labels with desired text value. For example:
private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) { int k = 0; ultraChart1.Annotations.Annotations.Clear(); foreach (Primitive pr in e.SceneGraph) { if (pr.GetType() == typeof(Text) && ((Text)pr).Path == "Border.Title.Grid.Y") { k++; string temp = ((Text)pr).GetTextString(); ((Text)pr).bounds.Offset(10, 0); ((Text)pr).SetTextString(temp + " Custom Label " + k.ToString()); ((Text)pr).bounds.Width = 100; } } }
Please take a look at the attached samples for more details and let me know if you have any questions.
Regards
This is WinForms sample
Here is the ASP application
Here is the whole code:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using Infragistics.UltraChart.Shared.Styles;using Infragistics.UltraChart.Resources.Appearance;using Infragistics.UltraChart.Core.Primitives;
namespace UltraChartRadarChart_2{ public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) {
this.ultraChart1.ChartType = ChartType.Composite;
ChartArea area = new ChartArea(); this.ultraChart1.CompositeChart.ChartAreas.Add(area);
ChartLayerAppearance myLayer = new ChartLayerAppearance(); myLayer.ChartType = ChartType.RadarChart; myLayer.ChartArea = area;
ultraChart1.Axis.X.Labels.FontColor = Color.Red; ultraChart1.Axis.Y.RangeType = AxisRangeType.Custom; ultraChart1.Axis.Y.RangeMin = 0; ultraChart1.Axis.Y.RangeMax = 50; ultraChart1.Axis.Y.NumericAxisType = NumericAxisType.Linear; ultraChart1.Axis.Y.TickmarkStyle = AxisTickStyle.DataInterval; ultraChart1.Axis.Y.Labels.Layout.Behavior = AxisLabelLayoutBehaviors.None;
DataTable dt = new DataTable(); dt.Columns.Add("Label", typeof(string)); dt.Columns.Add("Value", typeof(double));
dt.Rows.Add("My Label 1", 10); dt.Rows.Add("My Label 2", 20); dt.Rows.Add("My Label 3", 30); dt.Rows.Add("My Label 4", 40); dt.Rows.Add("My Label 5", 20); dt.Rows.Add("My Label 6", 30); dt.Rows.Add("My Label 7", 10); dt.Rows.Add("My Label 8", 20); dt.Rows.Add("My Label 9", 30); dt.Rows.Add("My Label 10", 10);
NumericSeries series1 = new NumericSeries(); series1.DataBind(dt, "Value", "Label"); series1.PEs.Add(new PaintElement(Color.Red)); myLayer.Series.Add(series1); this.ultraChart1.CompositeChart.Series.Add(series1); this.ultraChart1.CompositeChart.ChartLayers.Add(myLayer);
private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) { int k = 0; ultraChart1.Annotations.Annotations.Clear(); foreach (Primitive pr in e.SceneGraph) { if (pr.GetType() == typeof(Text) && ((Text)pr).Path == "Border.Title.Grid.Y") { k++; string temp = ((Text)pr).GetTextString(); BoxAnnotation BoxAnn = new BoxAnnotation(); BoxAnn.Location.Type = LocationType.Pixels; BoxAnn.Border.Thickness = 0; BoxAnn.TextStyle.FontColor = Color.DimGray; BoxAnn.Text = temp + " Custom Label " + k.ToString(); BoxAnn.Location.LocationX = ((Text)pr).bounds.X + 70; BoxAnn.Location.LocationY = ((Text)pr).bounds.Y; ultraChart1.Annotations.Add(BoxAnn); } }
} }}