Completed
Last Updated: 26 Jun 2015 07:34 by ADMIN
ADMIN
George
Created on: 22 May 2014 14:44
Category: ChartView
Type: Bug Report
0
FIX. RadChartView - setting certain shapes to DataPointElement causes the element not to paint
To reproduce:

Create a RadChartView with LineSeries. Subscribe to the CreatePointElement event and use the following code:

void Chart_CreatePointElement(object sender, ChartViewCreatePointElementEventArgs e)
{
    e.DataPointElement = new DataPointElement(e.DataPoint);
    e.DataPointElement.GradientStyle = GradientStyles.Solid;
    e.DataPointElement.GradientAngle = 270;
    e.DataPointElement.Shape = new DiamondShape();
    e.DataPointElement.BackColor = Color.Red;
    e.DataPointElement.BackColor2 = Color.Blue;
    e.DataPointElement.BackColor3 = Color.Blue;
    e.DataPointElement.BackColor4 = Color.Blue;
}

The elements paint when you use ChamferedRectShape.

Workaround 
class MyDiamondShape : ElementShape
{
    public override GraphicsPath CreatePath(Rectangle bounds)
    {
        GraphicsPath path = new GraphicsPath();
        
        path.AddPolygon(new PointF[]
        {
            new PointF(bounds.X + 0.5f * bounds.Width, bounds.Top),
            new PointF(bounds.Right, bounds.Y + 0.5f * bounds.Height),
            new PointF(bounds.X + 0.5f * bounds.Width, bounds.Bottom),
            new PointF(bounds.Left, bounds.Y + 0.5f * bounds.Height)
        });
    
        return path;
    }
}

class MyStarShape : ElementShape
{
    private int arms;
    private float innerRadiusRatio;
    
    public MyStarShape()
    {
        this.arms = 8;
        this.innerRadiusRatio = 0.2f;
    }
    
    /// <summary>
    /// Creates Star like shape. Overrides CreatePath method in the base class
    /// ElementShape.
    /// </summary>
    public override GraphicsPath CreatePath(Rectangle bounds)
    {
        GraphicsPath path = new GraphicsPath();
        
        double angle = Math.PI / arms;
        double offset = Math.PI / 2d;
        PointF center = new PointF(bounds.X + bounds.Width / 2f, bounds.Y + bounds.Height / 2f);
        PointF[] points = new PointF[arms * 2];
        
        for (int i = 0; i < 2 * arms; i++)
        {
            float r = (i & 1) == 0 ? bounds.Width / 2f : bounds.Width / 2f * innerRadiusRatio;
            
            float currX = center.X + (float)Math.Cos(i * angle - offset) * r;
            float currY = center.Y + (float)Math.Sin(i * angle - offset) * r;
        
            points[i] = new PointF(currX, currY);
        }
        
        path.AddPolygon(points);
        return path;
    }
}

class MyHeartShape : ElementShape
{
    public override GraphicsPath CreatePath(Rectangle bounds)
    {
        GraphicsPath path = new GraphicsPath();
        
        path.AddArc(new Rectangle(bounds.X, bounds.Y, bounds.Width / 2, bounds.Height / 2), 150, 210);
        path.AddArc(new Rectangle(bounds.X + bounds.Width / 2, bounds.Y, bounds.Width / 2, bounds.Height / 2), 180, 210);
        path.AddLine(path.GetLastPoint(), new Point(bounds.X + bounds.Width / 2, bounds.Bottom));
        path.CloseFigure();
    
        return path;
    }
    
}
0 comments