I'd like to show where our target productivity range should be in a line chart, kinda like this image (doctored in a photo editor). Anyone have any suggestions for accomplishing this? I would prefer a translucent band as shown.
Thanks,Trevor
Your code seems to work well for me. I have a feeling the results you are seeing have something to do with your data. Try this code and you should see the same result as the attached image.
public partial class Form1 : Form{ public Form1() { InitializeComponent(); }
List<MinMax> TargetRanges = new List<MinMax>(); private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) { if (TargetRanges == null) return;
if (TargetRanges.Count == 0) return;
foreach (MinMax mm in TargetRanges) { double minRange = mm.Min; double maxRange = mm.Max; if (e.Grid.Count == 0) return;
IAdvanceAxis xAxis = (IAdvanceAxis)e.Grid["X"]; IAdvanceAxis yAxis = (IAdvanceAxis)e.Grid["Y"];
Rectangle rangeBounds = new Rectangle(); rangeBounds.X = (int)xAxis.MapMinimum; rangeBounds.Y = (int)yAxis.Map(maxRange); rangeBounds.Width = (int)Math.Abs((xAxis.MapMaximum - xAxis.MapMinimum)); rangeBounds.Height = (int)Math.Abs((yAxis.Map(minRange) - yAxis.Map(maxRange))); Box rangeRect = new Box(rangeBounds); rangeRect.PE.StrokeOpacity = 0; rangeRect.PE.Fill = mm.RangeColor; rangeRect.PE.FillOpacity = 50; e.SceneGraph.Add(rangeRect); } }
private void Form1_Load(object sender, EventArgs e) { ultraChart1.ChartType = ChartType.LineChart; NumericSeries series = new NumericSeries(); series.Points.Add(new NumericDataPoint(1, "", false)); series.Points.Add(new NumericDataPoint(5, "", false)); series.Points.Add(new NumericDataPoint(3, "", false)); series.Points.Add(new NumericDataPoint(10, "", false)); series.Points.Add(new NumericDataPoint(0, "", false)); ultraChart1.Series.Add(series);
TargetRanges.Add(new MinMax() { Min = 1, Max = 2, RangeColor = Color.Green }); TargetRanges.Add(new MinMax() { Min = 3, Max = 4, RangeColor = Color.Blue }); TargetRanges.Add(new MinMax() { Min = 5, Max = 6, RangeColor = Color.Red }); TargetRanges.Add(new MinMax() { Min = 7, Max = 8, RangeColor = Color.Orange }); }}
public class MinMax{ public MinMax(){}
public double Min { get; set; } public double Max { get; set; } public Color RangeColor { get; set; }}
Thanks for the help Max. This is the method I call from the fillscenegraphevent:
private void PaintTargetRange(FillSceneGraphEventArgs e){if
(TargetRanges==null) return;if(TargetRanges.Length==0) return;foreach (MinMax mm in TargetRanges){ double minRange = mm.Min; double maxRange = mm.Max; if (e.Grid.Count == 0) return
;
Rectangle rangeBounds = new Rectangle();
rangeBounds.X = (
int)xAxis.MapMinimum; rangeBounds.Y = (int)yAxis.Map(maxRange); rangeBounds.Width = (int)Math.Abs((xAxis.MapMaximum - xAxis.MapMinimum)); rangeBounds.Height = (int)Math.Abs((yAxis.Map(minRange) - yAxis.Map(maxRange))); Box rangeRect = new Box(rangeBounds); rangeRect.PE.StrokeOpacity = 0; rangeRect.PE.Fill = mm.RangeColor; rangeRect.PE.FillOpacity = 50; e.SceneGraph.Add(rangeRect);}}
make sure every box is added via e.Scenegraph.Add method and that the min and max values are within the axis range. There shouldn't be anything special needed for any additional shapes. Can you post your code here if you're still having problems?
I since my chart requires several ranges, i tried a simple loop around all the code (through a number of min/max values), but only the very first box gets added. Is there something special i need to do to add a 2nd, 3rd, 4th box?
Awesome! That's exactly what I needed. Thanks a ton Max!