Search code examples
chartsreportingdundas

Extending a trend line to either side of a Dundas Chart


I hope somebody can help. I'm using Dundas Charting for Reporting Services v2.2 inside a Visual Studio 2005 Business Intelligence project. What I am trying to do is extend the point at the center of the series so that is spans across the entire chart area from the one side to the other.

So instead of just having a marker (even though the series is defined as a Line graph) in the center of the series I want a line that goes from 1 end of the chart to the other.

Please help.


Solution

  • I found the solution to the problem after much tinkering and googling. What I ended up doing was specifying 2 points on either side of the graph and then drawing a line between them. This is done in the 'Post Paint' event of the chart found in the Advanced section.

    I also added a parameter in the parameters section which contains the Y-Axis constant for the trend line.

    See the below code for the solution:

    // Parameter: chartObj     - represents the chart object 
    // Parameter: sender       - the chart object that will be painted
    // Parameter: e            - arguments that contain the graphics object
    // Parameter: codeParams   - user defined code parameters
    
    double stripValue = Double.Parse(codeParams["Std"].ToString()); 
    
    PointF p1 = new PointF(); 
    p1.X = (float)chartObj.ChartAreas["Default"].AxisX.Minimum; 
    p1.X = (float)chartObj.ChartAreas["Default"].AxisX.ValueToPixelPosition(p1.X); 
    
    p1.Y = (float)chartObj.ChartAreas["Default"].AxisY.ValueToPixelPosition(stripValue); 
    
    
    PointF p2 = new PointF(); 
    p2.X = (float)chartObj.ChartAreas["Default"].AxisX.Maximum; 
    p2.X = (float)chartObj.ChartAreas["Default"].AxisX.ValueToPixelPosition(p2.X); 
    
    p2.Y = (float)chartObj.ChartAreas["Default"].AxisY.ValueToPixelPosition(stripValue); 
    
    
    e.ChartGraphics.Graphics.DrawLine(new Pen(Color.FromArgb(255, 0, 0, 0), 1), p1, p2);