Hello all,
I am trying to mimic the Excel graph shown so that the red lines between the 2nd and 3rd lines to show the spread. Is there anyway to do this in UltraChart? Also, I am trying to get the week to show on the x-axis. I am pulling the week in from a DB2 database, and the dates are returning as required.
Thanks for all the help in advance!
This is only possible with the help of FillSceneGraph event. Here I’m using a polygon with a hatch. If you need to add each vertical line manually, you can always do that, too, since you already have the points. I’m not really sure what you mean by displaying the weeks. Does that mean week numbers? I don’t think there’s a string format that does that, and if so, you’ll need to implement IRenderLabel , find the week number from the date and insert is as a string into the label.
private void Form1_Load(object sender, EventArgs e) { ultraChart1.Data.DataSource = new int[,] { {1,2,1,3,2,4,3,5,4,5}, {4,5,4,7,4,7,6,7,9,8} }; } private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e) { List lines = new List(); List points = new List(); foreach (var p in e.SceneGraph) { if (p is Polyline) lines.Add(p as Polyline); } if (lines.Count < 2) return; foreach (var point in lines[0].points) { points.Add(point.point); } foreach (var point in lines[1].points.Reverse()) { points.Add(point.point); } Polygon area = new Polygon(points.ToArray()); PaintElement pe = new PaintElement(); pe.ElementType = PaintElementType.Hatch; pe.Hatch = FillHatchStyle.Vertical; pe.Fill = Color.Red; pe.FillStopColor = Color.Transparent; area.PE = pe; e.SceneGraph.Add(area); }
Dave,
Thanks for your help, but I have having trouble following the code (due to the lack of knowledge of paint elements and winchart). I am actually using a composite chart with 2 layers where 2 lines that are needing connected are on the same layer. Do you have any .NET code that could be of use to me?
Thanks!
Here’s how you’d do this with a composite chart. Pretty much works if you paste the code, provided you got a chart on the form and got the FillSceneGraph event hooked up.
private void Form1_Load(object sender, EventArgs e) { ultraChart1.ChartType = ChartType.Composite; ChartArea area = new ChartArea(); ultraChart1.CompositeChart.ChartAreas.Add(area); AxisItem xAxis = new AxisItem(ultraChart1, AxisNumber.X_Axis); xAxis.SetLabelAxisType = SetLabelAxisType.ContinuousData; xAxis.DataType = AxisDataType.String; area.Axes.Add(xAxis); AxisItem yAxis = new AxisItem(ultraChart1, AxisNumber.Y_Axis); yAxis.DataType = AxisDataType.Numeric; area.Axes.Add(yAxis); NumericSeries series1 = new NumericSeries(); series1.Points.Add(new NumericDataPoint(2, "", false)); series1.Points.Add(new NumericDataPoint(3, "", false)); series1.Points.Add(new NumericDataPoint(2, "", false)); series1.Points.Add(new NumericDataPoint(3, "", false)); NumericSeries series2 = new NumericSeries(); series2.Points.Add(new NumericDataPoint(5, "", false)); series2.Points.Add(new NumericDataPoint(6, "", false)); series2.Points.Add(new NumericDataPoint(4, "", false)); series2.Points.Add(new NumericDataPoint(7, "", false)); ultraChart1.CompositeChart.Series.Add(series1); ultraChart1.CompositeChart.Series.Add(series2); ChartLayerAppearance layer = new ChartLayerAppearance(); layer.ChartArea = area; layer.AxisX = xAxis; layer.AxisY = yAxis; layer.ChartType = ChartType.LineChart; layer.Series.Add(series1); layer.Series.Add(series2); ultraChart1.CompositeChart.ChartLayers.Add(layer); } private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e) { if (e.SceneGraph.Count == 0 || ultraChart1.CompositeChart.ChartLayers.Count == 0) return; ChartLayerAppearance myLayer = ultraChart1.CompositeChart.ChartLayers[0]; List lines = new List(); List points = new List(); foreach (var p in e.SceneGraph) { Polyline polyline = p as Polyline; if (polyline != null && polyline.Layer == myLayer.ChartLayer) { lines.Add(polyline); } } if (lines.Count < 2) return; foreach (var point in lines[0].points) { points.Add(point.point); } foreach (var point in lines[1].points.Reverse()) { points.Add(point.point); } Polygon area = new Polygon(points.ToArray()); PaintElement pe = new PaintElement(); pe.ElementType = PaintElementType.Hatch; pe.Hatch = FillHatchStyle.Vertical; pe.Fill = Color.Red; pe.FillStopColor = Color.Transparent; area.PE = pe; e.SceneGraph.Add(area); }
Thanks! The code worked perfectly after converting it to VB!