Hi,
I am atemping to add line label for each line in my scatter line chart. Since I don't use series, I use a datatable which has several columns, I swap the rows and columns to draw the line chart.. I wonder is there any way that I can set the line label? Thank you.
My code is as follows:
UltraChart1.ChartType = ChartType.ScatterLineChart;GrowthChart growth = new GrowthChart();DataTable dt1 = growth.SearchByGenderType("M", "Length");
UltraChart1.Axis.X.RangeMin = 0;UltraChart1.Axis.X.RangeMax = 40;UltraChart1.Axis.X.RangeType = AxisRangeType.Custom;
UltraChart1.Axis.Y.RangeMin = 0;UltraChart1.Axis.Y.RangeMax = 120;UltraChart1.Axis.Y.RangeType = AxisRangeType.Custom;
UltraChart1.Axis.X2.RangeMin = 0;UltraChart1.Axis.X2.RangeMax = 40;UltraChart1.Axis.X2.RangeType = AxisRangeType.Custom;
UltraChart1.Axis.Y2.RangeMin = 0;UltraChart1.Axis.Y2.RangeMax = 120;UltraChart1.Axis.Y2.RangeType = AxisRangeType.Custom;
UltraChart1.ScatterLineChart.LineData.DataSource = dt1;UltraChart1.ScatterLineChart.LineData.SwapRowsAndColumns = true;UltraChart1.ScatterLineChart.LineData.DataBind();
DataTable dt = new DataTable();dt.Columns.Add("X-Axis", typeof(decimal));dt.Columns.Add("Y-Axis", typeof(decimal));dt.Rows.Add(new object[] { 6.5, 80 });dt.Rows.Add(new object[] { 20, 90 });
UltraChart1.ScatterLineChart.ScatterData.DataSource = dt;UltraChart1.ScatterLineChart.ScatterData.DataBind();UltraChart1.ScatterLineChart.Scatter.ColumnX = 0;UltraChart1.ScatterLineChart.Scatter.ColumnY = 1;
UltraChart1.ScatterLineChart.LineData.UseRowLabelsColumn = true;UltraChart1.ScatterLineChart.LineData.RowLabelsColumn = 0;
You could modify the scene graph by the FillSceneGraph event of the chart. Here is a link describing the event and you could find in the forum a lot of samples too.
Let me know if you have further questions.
By the way, you might have to click the graph to zoom in to find the line labels truncated by screen.
As I see the image, the FillSceneGraph is what you need. Here is a sample code with a sample data which adds a textbox to the before last point of the polyline. Please, review it and let me know if you need a further assistance.
protected void Page_Load(object sender, EventArgs e){ UltraChart UltraChart1 = new UltraChart(); this.Form.Controls.Add(UltraChart1); UltraChart1.ChartType = ChartType.ScatterLineChart; DataTable lineData = new DataTable(); lineData.Columns.Add("label", typeof(string)); lineData.Columns.Add("Value", typeof(double)); DataTable scatterData = new DataTable(); scatterData.Columns.Add("ValueX", typeof(double)); scatterData.Columns.Add("ValueY", typeof(double)); lineData.Rows.Add(new object[] { "item 1", 10 }); lineData.Rows.Add(new object[] { "item 2", 11 }); lineData.Rows.Add(new object[] { "item 3", 12 }); lineData.Rows.Add(new object[] { "item 4", 11 }); lineData.Rows.Add(new object[] { "item 5", 13 }); scatterData.Rows.Add(new object[] { 2, 2 }); scatterData.Rows.Add(new object[] { 4, 4 }); scatterData.Rows.Add(new object[] { 6, 6 }); scatterData.Rows.Add(new object[] { 8, 8 }); UltraChart1.ScatterLineChart.LineData.DataSource = lineData;//dt1; UltraChart1.ScatterLineChart.LineData.SwapRowsAndColumns = true; UltraChart1.ScatterLineChart.LineData.DataBind(); DataTable dt = new DataTable(); dt.Columns.Add("X-Axis", typeof(decimal)); dt.Columns.Add("Y-Axis", typeof(decimal)); dt.Rows.Add(new object[] { 6.5, 80 }); dt.Rows.Add(new object[] { 20, 90 }); UltraChart1.ScatterLineChart.ScatterData.DataSource = scatterData;// dt; UltraChart1.ScatterLineChart.ScatterData.DataBind(); UltraChart1.ScatterLineChart.Scatter.ColumnX = 0; UltraChart1.ScatterLineChart.Scatter.ColumnY = 1; UltraChart1.ScatterLineChart.LineData.UseRowLabelsColumn = true; UltraChart1.ScatterLineChart.LineData.RowLabelsColumn = 0; UltraChart1.Data.DataBind(); UltraChart1.FillSceneGraph += new Infragistics.UltraChart.Shared.Events.FillSceneGraphEventHandler(UltraChart1_FillSceneGraph);}void UltraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e){ List<Text> texts = new List<Text>(); // loop trough the scene graph collection to get all polylines and create text box with // start coordinates the before last point coordinates foreach (Primitive p in e.SceneGraph) { Polyline line = p as Polyline; if (line == null) { continue; } LineLayer lineLayer = line.Layer as LineLayer; if (lineLayer != null) { // get the desired text you want to add to the line -> you could get whatever data you want to display String textString = lineLayer.ChartData.GetColumnLabel(line.Column).ToString(); // find the coordinates of the point we want to add the text too Point beforeLastPoint = line.points[line.points.Length - 2].point; Text text = new Text(); text.PE.Fill = Color.Red; // set the bounds of the text to be a rectangle with start point the before last point // you can set whatever coordinates you need text.bounds = new Rectangle(beforeLastPoint.X, beforeLastPoint.Y, 100, 20); text.SetTextString(textString); texts.Add(text); } } foreach (Text t in texts) { e.SceneGraph.Add(t); }}
It does the trick! Thank you very very much!!