C # using nplot plotting skills

Source: Internet
Author: User
C # nplot plotting skills

(19:14:05)

Tags:

Cnplot drawing it
Category:Learning

/// Add the downloaded nplot. DLL to the toolbox, drag a control to the form, and declare using nplot;

 

/////// Print and save the drawn graph //////////
Private void
Print ()
{

Myplot. Print (true );
}
Private void save ()
{

Savefiledialog1.filter =
"Bitmap
(*. BMP) | *. BMP | JPEG (*. JPG) | *. JPG ;*. JPEG; *, jpe | GIF (*. GIF) | *. GIF | tiff (*. tiff) | *. tiff | PNG (*. PNG) | *. PNG | EXIF (*. EXIF) | *. EXIF |
All files (*. *) | *.*";

If
(Savefiledialog1.showdialog () = dialogresult. OK)
{

Try

{

Int H = myplot. Size. height;

Int W = myplot. Size. width;

Bitmap Bm = new Bitmap (W, H );

Bitmap bm1 = new Bitmap (W, H );

Rectangle RT = new rectangle (1, 1, W, H );

Savefiledialog1.restoredirectory = true;

Savefiledialog1.createprompt = true;

Myplot. drawtobitmap (BM, RT );

If (savefiledialog1.filterindex = 1)

{

BM. Save (savefiledialog1.filename );

}

If (savefiledialog1.filterindex = 2)

{

BM. Save (savefiledialog1.filename, imageformat. JPEG );

}

If (savefiledialog1.filterindex = 3)

{

BM. Save (savefiledialog1.filename, imageformat. GIF );

}

If (savefiledialog1.filterindex = 4)

{

BM. Save (savefiledialog1.filename, imageformat. Tiff );

}

If (savefiledialog1.filterindex = 5)

{

BM. Save (savefiledialog1.filename, imageformat. PNG );

}

If (savefiledialog1.filterindex = 6)

{

BM. Save (savefiledialog1.filename, imageformat. EXIF );

}

}

Catch (exception myex)

{

MessageBox. Show (myex. tostring (), "error prompt", messageboxbuttons. OK,
Messageboxicon. Warning );

}
}
}

// zoom in and out
private void changesize ()
{< br>
This. myplot. xaxis1.increaserange (0.1);
This. myplot. yaxis1.increaserange (0.1); // zoom out
This. myplot. xaxis1.increaserange (-0.1);
This. myplot. yaxis1.increaserange (-0.1); /// zoom in
This. myplot. refresh ();
}< br> //////// various plotting ////////

Private void plot ()
{

This. myplot. Clear (

//// // Tag //////////
String []
Strlabel = new string [Leng];
For (INT I =
0; I <Leng; I ++)

Strlabel [I] = convert. tostring (P [I]);

Labelpointplot labp = new labelpointplot ();

Labp. abscissadata = X;

Labp. ordinatedata = P;

Labp. textdata = strlabel;

Labp. labeltextposition = labelpointplot. labelpositions. above;
Labp. Marker
= New marker (Marker. markertype. Square, 8 );

Labp. Marker. Color = color. blue;

Myplot. Add (labp );

Myplot. Refresh ();

//// // Grid //////////

Grid mygrid = new grid ();

Mygrid. horizontalgridtype = grid. gridtype. Fine;

Mygrid. verticalgridtype = grid. gridtype. Fine;

This. myplot. Add (mygrid );
//// // Curve, Dual Axis //////////
//// // Horizontal line //////////

Horizontalline line = new horizontalline (1.2 );

Line. lengthscale = 0.89f;

This. myplot. Add (line,-10 );
//// // Vertical line ///////////
Verticalline
Line2 = new verticalline (1.2 );

Line2.lengthscale = 0.89f;

This. myplot. Add (line2 );
///// Normal line ///////////
Lineplot lp3
= New lineplot ();

Lp3.ordinatedata = ypw;

Lp3.abscissadata = X;
Lp3.pen =
New pen (color. Orange );

Lp3.pen. width = 2;
Lp3.label =
"Price ";

This. myplot. Add (lp3 );
Linearaxis
Linx = (linearaxis) myplot. xaxis1;

This. myplot. xaxis1 = Linx;
Linearaxis
Liny = (linearaxis) myplot. yaxis1;
Liny. Label =
"Price ";

Liny. axiscolor = color. Orange;

Liny. labelcolor = color. Orange;

Liny. ticktextcolor = color. Orange;

This. myplot. yaxis1 = Liny;
Lineplot lp4
= New lineplot ();

Lp4.ordinatedata = yuw;

Lp4.abscissadata = X;
Lp4.pen =
New pen (color. Green );

Lp4.pen. width = 2;
Lp4.label =
"Sales volume ";

This. myplot. Add (lp4, plotsurface2d. xaxisposition. Top,
Plotsurface2d. yaxisposition. Right );
Linearaxis
Liny2 = (linearaxis) myplot. yaxis2;

Liny2.worldmax = 1.2;

Liny2.worldmin = 0;
Liny2.label
= "Sales volume ";

Liny2.axiscolor = color. Green;

Liny2.labelcolor = color. Green;

Liny2.ticktextcolor = color. Green;

This. myplot. yaxis2 = liny2;
//// // Legend //////////

This. myplot. Legend = new legend ();

This. myplot. Legend. attachto (plotsurface2d. xaxisposition. Top,
Plotsurface2d. yaxisposition. Right );

This. myplot. Legend. numberitemshorizontally = 2;

This. myplot. Legend. horizontaledgeplacement =
Legend. Placement. inside;

This. myplot. Legend. verticaledgeplacement =
Legend. Placement. inside;

This. myplot. Legend. yoffset = 5;

This. myplot. Legend. xoffset =-5;
 
//// // Move the form //////////

This. myplot. addinteraction (New
Nplot. Windows. plotsurface2d. Interactions. horizontaldrag ());

This. myplot. addinteraction (New
Nplot. Windows. plotsurface2d. Interactions. verticaldrag ());

This. myplot. addinteraction (New
Nplot. Windows. plotsurface2d. Interactions. axisdrag (true ));
///// The column chart that has been accumulated ////////

Histogramplot hp3 = new histogramplot ();

Hp3.abscissadata = X;

Hp3.ordinatedata = ycc1;

Hp3.basewidth = 0.6f;

Hp3.rectanglebrush = rectanglebrushes. Vertical. faintbluefade;
Hp3.filled =
True;
Hp3.label =
"January ";

Histogramplot hp4 = new histogramplot ();

Hp4.abscissadata = X;

Hp4.ordinatedata = ycc2;
Hp4.label =
"February ";

Hp4.rectanglebrush =
Rectanglebrushes. Horizontal. faintgreenfade;
Hp4.filled =
True;

Hp4.stackedto (hp3 );

This. myplot. Add (hp3 );

This. myplot. Add (hp4 );
 
///// Level chart ////////

Stepplot SP1
= New stepplot ();

Sp1.ordinatedata = ych1;

Sp1.abscissadata = X;
Sp1.label =
"Height ";

Sp1.pen. width = 2;

Sp1.pen. Color = color. blue;

This. myplot. Add (SP1 );

//// Point chart ////////

Marker M =
New marker (Marker. markertype. cross1, 6, new pen (color. Blue,
2.0f ));
Pointplot PP
= New pointplot (m );

Pp. ordinatedata =;

Pp. abscissadata = new startstep (-500.0, 10.0 );
Pp. Label =
"Random ";

This. myplot. Add (PP );

//// Image ////////

Double [,] map = new double [19, 19];
For (INT I =
0; I <19; ++ I)
{

For (Int J = 0; j <19; ++ J)

{

Map [I, j] = convert. todouble (tokens [I * 19 + J], new

System. Globalization. cultureinfo ("En-us "));

}
}
Imageplot IP
= New imageplot (MAP,-9.0f, 1.0f,-9.0f, 1.0f );
IP. Gradient
= New lineargradient (color. Gold, color. Black );

This. myplot. smoothingmode =
System. Drawing. drawing2d. smoothingmode. None;

This. myplot. addinteraction (New
Nplot. Windows. plotsurface2d. Interactions. rubberbandselection ());


This. myplot. add (IP);

/// // candle chart //
int [] opens
= {1, 2, 1, 2, 1, 3 };
double []
closes = {2, 2, 2, 1, 2, 1 };
float [] lows
={ 0, 1, 1, 1, 0, 0};
system. int64 [] highs = {3, 2, 3, 3, 3, 4
};
int [] Times
={ 0, 1, 2, 3, 4, 5 };
candleplot
CP = new candleplot ();
CP. closedata
= closes;
CP. opendata
= opens;
CP. lowdata =
lows;
CP. highdata
= highs;
CP. abscissadata = times;
This. myplot. add (CP);
///// log coordinate axis //////

//
X axis
Logaxis
Logax = new logaxis (plotsurface. xaxis1 );

Logax. worldmin = xmin;

Logax. worldmax = xmax;

Logax. axiscolor = color. Red;

Logax. labelcolor = color. Red;

Logax. ticktextcolor = color. Red;

Logax. largetickstep = 1.0f;
Logax. Label
= "X ";

This. myplot. xaxis1 = logax;
// Y
Axis

Logaxis logay = new logaxis (plotsurface. yaxis1 );

Logay. worldmin = ymin;

Logay. worldmax = Ymax;

Logay. axiscolor = color. Red;

Logay. labelcolor = color. Red;

Logay. ticktextcolor = color. Red;

Logay. largetickstep = 1.0f;
Logay. Label
= "X ^ 2 ";

This. myplot. yaxis1 = logay;
//// Character axis ////////
Labelaxis
La1 = new labelaxis (this. myplot. xaxis1 );
String [] SX
= New string [15];
For (INT I =
0; I <15; I ++)
{

La1.addlabel (SX [I]. tostring (), I );
}
La1.label =
"Time ";

La1.ticktextfont = new font ("Courier New", 10 );

La1.ticksbetweentext = true;

This. myplot. xaxis1 = la1;
//// Area coloring ////////

Filledregion
Fr = new filledregion (New verticalline (1.2), new
Verticalline (2.4 ));
// The area between the two lines: filledregion Fr = new filledregion (lp1,
Lp2 );

Fr. Brush = brushes. blanchedalmond;

This. myplot. Add (FR );
///// Draw an arrow //////////
Arrowitem
= New arrowitem (New pointd (2, 4), 360-(30-90), "Arrow ");
A. headoffset
= 5;
A. arrowcolor
= Color. Red;
A. textcolor
= Color. Purple;

This. myplot. Add ();


This. myplot. Refresh ();
}

Related Article

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.