Jfreechart demo (not Java ee)

Source: Internet
Author: User

Three packages need to be added
Gnujaxp. Jar
Jcommon-1.0.17.jar
Jfreechart-1.0.14.jar

<! -- Jfreechart needs to be added to/webroot/WEB-INF/Web. XML to display the image -->
<Servlet>
<Servlet-Name> displaychart </servlet-Name>
<Servlet-class> org. jfree. Chart. servlet. displaychart </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> displaychart </servlet-Name>
<URL-pattern>/servlet/displaychart </url-pattern>
</Servlet-mapping>


Solutions to Chinese garbled characters
// Create a topic Style
Standardcharttheme = new standardcharttheme ("cn ");
// Set the title Font
Standardcharttheme. setextralargefont (new font ("", Font. Bold, 20 ));
// Set the font of the legend
Standardcharttheme. setregularfont (new font ("", Font. Plain, 15 ));
// Set the axial font
Standardcharttheme. setlargefont (new font ("", Font. Plain, 15 ));
// Apply the topic Style

Chartfactory. setcharttheme (standardcharttheme );

Code: % %

/**

* Jfreechartone. Java

* Author: Longlong

* May 31,200 7

*/

Package com. GHG. Java;

 

Import java. AWT. Font;

Import javax. Swing. jpanel;

Import org. jfree. Chart. chartfactory;
Import org. jfree. Chart. standardcharttheme;

Import org. jfree. Chart. chartpanel;

Import org. jfree. Chart. jfreechart;

Import org. jfree. Chart. Plot. pieplot;

Import org. jfree. Chart. Plot. plotorientation;

Import org. jfree. Data. Category. categorydataset;

Import org. jfree. Data. Category. defaultcategorydataset;

Import org. jfree. Data. General. defaultpiedataset;

Import org. jfree. Data. General. piedataset;

Import org. jfree. UI. applicationframe;

 

Public class jfreechartone extends applicationframe {

Private Static final long serialversionuid = 1l;

Public jfreechartone (string S)

{

Super (s );

Setcontentpane (createjpanel ());

}

Public static void main (string [] ARGs ){

Jfreechartone one = new jfreechartone ("cityinfoport organization structure ");

One. Pack ();

One. setvisible (true );

}

// Use the static method to set the data source (pie chart)

Public static piedataset createpiedataset (){

Defaultpiedataset defapipiedataset = new defaultpiedataset ();

Defaultpiedataset. setvalue ("Administrator", 10.02d );

Defaultpiedataset. setvalue ("market personnel", 42423d );

Defaultpiedataset. setvalue ("Developer", 601_2d );

Defaultpiedataset. setvalue ("OEM", 10.02d );

Defaultpiedataset. setvalue ("other personnel", 5.11d );

Return defaultpiedataset;

}

// Create a jfreechart instance through chartfactory

Public static jfreechart createjfreechart (piedataset P)

{
// Create a topic Style
Standardcharttheme = new standardcharttheme ("cn ");
// Set the title Font
Standardcharttheme. setextralargefont (new font ("", Font. Bold, 20 ));
// Set the font of the legend
Standardcharttheme. setregularfont (new font ("", Font. Plain, 15 ));
// Set the axial font
Standardcharttheme. setlargefont (new font ("", Font. Plain, 15 ));
// Apply the topic Style
Chartfactory. setcharttheme (standardcharttheme );

Jfreechart A = chartfactory. createpiechart ("cityinfoport Organization Structure", P, true );

Pieplot PIE = (pieplot) A. getplot ();

Pie. setlabelfont (new font ("sansserif", Font. Bold, 12 ));

Pie. setnodatamessage ("No data available ");

Pie. setcircular (true );

Pie. setlabelgap (0.01d); // spacing

Return;

}

Public static jpanel createjpanel (){

Jfreechart = createjfreechart (createpiedataset ());

Return new chartpanel (jfreechart );

}

}

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.