Zedgraph adds a value to linechart

Source: Internet
Author: User

Zedgraph, a powerful open-source chart control supporting. net, is the latest version.

New update as of 28-nov-2007Version 5.1.4 + 4.6.4

Official homepage: http://zedgraph.org/

Sourceforg home page: http://zedgraph.sourceforge.net/

5. x supports. net2.0, and 4. x supports. net1.1. For personal reasons, the version used here is 5.1.1, and the method is similar.

 

Because it is open-source, a lot of code can be found in the sample, but there is no linechart addition method in the example. By referring to the method of adding values to barchart In the example, a feasible solution is provided here.

All the elements in zedgraph are drawn by using the GDI + technique. In fact, we need to create several textobject files and add them to the chart. Before that, we need to find the position of each vertex.

The practice is also very simple.

Masterpane. axischange (g );

Add the following code:

 

Int ord = 0;
Foreach (curveitem mycurve in mypane. curvelist)
{
Lineitem line = curve as lineitem;

If (line! = NULL)
{
Ipointlist points = mycurve. Points;

For (INT I = 0; I <points. Count; I ++)
{
Double xval = points [I]. X;
Double yval = points [I]. Y;

String lab = yval. tostring ("0.00") + "% ";

Textobj text = new textobj (lab, (float) xval, (float) yval * 1.01 );

Text. Location. coordinateframe = coordtype. axisxyscale;
Text. fontspec. size = 10;

Text. Location. alignh = alignh. Center;
Text. Location. alignv = alignv. bottom;
Text. fontspec. Border. isvisible = false;

Text. fontspec. angle = 0;
Text. fontspec. Fill. isvisible = false;

Mypane. graphobjlist. Add (text );
}
}

Ord ++;
}

Note:

  1. In earlier versions of zedgraph, the name of textobj is textitem.
  2. Masterpane. axischange (g); the statement in earlier versions is base. zedgraphcontrol. axischange ();
  3. The current version type of curve. Points is ipointlist, and the early version is pointpairlist.
  4. In this Code, (float) yval * 1.01 is used to generate an upward offset, because you do not know the specific height of the Y axis, if strong displacement is used, the offset effect cannot be reached because the Y axis scale is too short.

Last:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.