Click here to Skip to main content
11,716,133 members (87,965 online)
Click here to Skip to main content

Bezier curve for the Microsoft Web Chart control

, 17 Mar 2011 CPOL 17.2K 476 19
Rate this:
Please Sign up or sign in to vote.
Adds a new series that can be used in the MS Web Chart control which will draw a Bezier curve for the construction points you define.

Introduction

This is an add-on for the Microsoft Web Chart control. It is a new series type that draws a Bezier curve according to the points you pass.

Using the code

I recently needed a Bezier graph in a web app. The Microsoft Web Chart control (which is actually the Dundas chart control) is a powerful control, so I added the functionality I needed to it. For the calculation of the Bezier curve itself, I used code from a CodeProject article by Tolga Birdal, you can find his work here. I encapsulated his code in a class called CalcBezierCurve. Then I created a new class BezierSeries which inherits from System.Web.UI.DataVisualization.Charting.Series. So you can use it in any chart from the Web Chart control.

/// <span class="code-SummaryComment"><summary>
</span>

The usage is quite simple (I assume you have a web form with a chart control called Chart1 on it):

protected void Page_Load(object sender, EventArgs e)
{
    //points to calculate the bezier graph
    List<DataPoint> bezierPoints = new List<DataPoint>();
    bezierPoints.Add(new DataPoint(0, 0));
    bezierPoints.Add(new DataPoint(3, 5));
    bezierPoints.Add(new DataPoint(5, 2));

    //chart control setup
    Chart1.Series.Clear();
    Chart1.ChartAreas.Clear();

    //bezier points chart
    ChartArea bezierPointsArea = new ChartArea("BezierPointsArea");
    Chart1.ChartAreas.Add(bezierPointsArea);
    Series bezierPointSeries = new Series("BezierPoints");
    bezierPointSeries.ChartType = SeriesChartType.Point;

    foreach (DataPoint bezierPoint in bezierPoints)
    {
        bezierPointSeries.Points.Add(bezierPoint);
    }

    Chart1.Series.Add(bezierPointSeries);

    //bezier curve chart
    ChartArea bezierCurveArea = new ChartArea("BezierCurveArea");
    Chart1.ChartAreas.Add(bezierCurveArea);
    //create instance of our bezier series
    BezierSeries bezierSeries = new BezierSeries();
    bezierSeries.Name = "BezierCurve";
    //set number of points, default is 1000
    bezierSeries.PointsOnCurve = 100;
    //set points which should be used to calc the bezier graph
    bezierSeries.BezierPoints = bezierPoints;
    Chart1.Series.Add(bezierSeries);
}

And this is the result:

Bezier graph

History

  • 2011-03-17 V 1.0: Initial version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rainer Halanek
Software Developer (Senior)
Austria Austria
Born and living in Vienna, Austria. Started with Pascal in 1993 and MS-DOS 5.0. After that a little C++ in OS/2 and loads of VBA with Access in Windows 95,98, NT. To get more professionel I started C# in 2002 and did some MCP exams on that. After working for my own company I got hired by different companies. Currently I'm employed at the Federal Chambers of Commerce as a Senior Software Engineer.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
all_in_flames23-Mar-11 7:50
memberall_in_flames23-Mar-11 7:50 
GeneralRe: My vote of 5 Pin
Rainer Halanek29-Mar-11 9:49
memberRainer Halanek29-Mar-11 9:49 
GeneralSome problems Pin
dherrmann22-Mar-11 22:01
memberdherrmann22-Mar-11 22:01 
AnswerRe: Some problems [modified] Pin
Rainer Halanek22-Mar-11 22:41
memberRainer Halanek22-Mar-11 22:41 
GeneralRe: Some problems Pin
dherrmann23-Mar-11 0:18
memberdherrmann23-Mar-11 0:18 
GeneralRe: Some problems Pin
Rainer Halanek23-Mar-11 0:29
memberRainer Halanek23-Mar-11 0:29 
GeneralSome problems Pin
dherrmann22-Mar-11 22:00
memberdherrmann22-Mar-11 22:00 
AnswerRe: Some problems Pin
Rainer Halanek22-Mar-11 22:34
memberRainer Halanek22-Mar-11 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150901.1 | Last Updated 17 Mar 2011
Article Copyright 2011 by Rainer Halanek
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid