I use FillSceneGraph to display a number of types on the graph. For example if a Y axis value is below some limit i draw a Ellipse around the symbol. I also draw lines and text with no issue EXCEPT for a single Text object that i draw at the bottom left corner of the graph that contains the date and time the graph was generated.
All good so far.
When i print the graph all objects display and print in the correct position EXCEPT this Text ofject that ends up being drawn in the middle of the graph.
code:
targetLabel = New Infragistics.UltraChart.Core.Primitives.Text()
targetLabel.SetTextString(labelText)
targetLabelSize = Size.Ceiling(Infragistics.UltraChart.Core.Util.Platform.GetLabelSizePixels(targetLabel.GetTextString(), targetLabel.labelStyle))
targetLabel.bounds = New Rectangle(5, UltraChart1.Height - targetLabelSize.Height - 5, targetLabelSize.Width, targetLabelSize.Height)
e.SceneGraph.Add(targetLabel)
Pat,
I would like to try to reproduce this. What chart style is your graph?
Have you been able to straighten this out?
Not yet. even switching to an Annotation has its drawbacks. Seems like the anchor point for an Annotation is centerred vertically and horizontally.
i just want to add text in the bottom left corner that has the date and time and some text.
Is there an easier way?
Thanks
pat
You could simply place a label over the chart in that lower left-hand corner and display the information that way, but if you really want to do this in the FillSceneGraph event you could do something like this:
private void Form1_Load(object sender, EventArgs e)
{
UltraChart chart = new UltraChart();
chart.Dock = DockStyle.Fill;
chart.ChartType = ChartType.Composite;
ChartArea area = new ChartArea();
chart.CompositeChart.ChartAreas.Add(area);
AxisItem x = new AxisItem(chart, AxisNumber.X_Axis);
x.DataType = AxisDataType.String;
x.SetLabelAxisType = Infragistics.UltraChart.Core.Layers.SetLabelAxisType.GroupBySeries;
AxisItem y = new AxisItem(chart, AxisNumber.Y_Axis);
y.DataType = AxisDataType.Numeric;
area.Axes.Add(x);
area.Axes.Add(y);
NumericSeries series = new NumericSeries();
series.Points.Add(new NumericDataPoint(1, "", false));
series.Points.Add(new NumericDataPoint(2, "", false));
series.Points.Add(new NumericDataPoint(3, "", false));
chart.Series.Add(series);
ChartLayerAppearance layer = new ChartLayerAppearance();
layer.ChartArea = area;
layer.AxisX = x;
layer.AxisY = y;
layer.ChartType = ChartType.ColumnChart;
layer.Series.Add(series);
chart.CompositeChart.ChartLayers.Add(layer);
Controls.Add(chart);
chart.FillSceneGraph += (o, args) =>
Text label = new Text();
label.SetTextString("custom label");
Size labelSize = Size.Ceiling(Platform.GetLabelSizePixels(label.GetTextString(), label.labelStyle));
label.bounds = new Rectangle(5, chart.Height - labelSize.Height - 5, labelSize.Width, labelSize.Height);
args.SceneGraph.Add(label);
};
}
You will need a reference to the UltraWinChart and the following "using" statements:
using Infragistics.UltraChart;
using Infragistics.UltraChart.Core.Layers;
using Infragistics.UltraChart.Resources.Appearance;
using Infragistics.UltraChart.Shared;
using Infragistics.UltraChart.Shared.Styles;
using Infragistics.Win;
using Infragistics.Win.UltraWinChart;
using Infragistics.UltraChart.Core.Primitives;
using Infragistics.UltraChart.Core.Util;
Try that and let me know how it goes.
I'm glad it works perfectly. Let me know if you have further questions.
Thanks! Works perfectly.
Here is my VB.net version
Dim chartSize As Size
chartSize = UltraChart1.Size
Dim titleLayer As TitleLayer
titleLayer = e.ChartCore.GetTitleLayer()
If Not titleLayer.OuterBound.IsEmpty() Then
chartSize = titleLayer.OuterBound.Size
End If
Dim targetLabel As Infragistics.UltraChart.Core.Primitives.Text
Dim targetLabelSize As Size
targetLabelSize = Size.Ceiling(Infragistics.UltraChart.Core.Util.Platform.GetLabelSizePixels(targetLabel.GetTextString(),targetLabel.labelStyle))
targetLabel.bounds = New Rectangle(5, chartSize.Height - targetLabelSize.Height - 5, targetLabelSize.Width, targetLabelSize.Height)
The PrintPreview changes the size of the Chart o fit the page so we have to get the Chart's true bounds inside FillSceneGraph. Try this code inside the FillSceneGraph event instead of the code I gave you before:
Size chartSize = chart.Size;
TitleLayer titleLayer = args.ChartCore.GetTitleLayer();
if (!titleLayer.OuterBound.IsEmpty)
chartSize = titleLayer.OuterBound.Size;
label.SetTextString("Date with text");
label.bounds = new Rectangle(5, chartSize.Height - labelSize.Height - 5, labelSize.Width, labelSize.Height);
I am attaching here a sample application which uses this code so you can see it in action. Let me know if you have further questions.
OK, I tried it with the PrintPreviewDialog and I see what you mean. I will show this to my developer and get back to you early in the week.
I will try your code and get back to you.