java智能图表类库jchartlib使用介绍-亚博电竞手机版

本文由码农网 – 小峰原创,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划!

jchartlib是一款基于java的智能图表类库,jchartlib不仅有着漂亮的外观,而且支持图表坐标数值的自动调整,这样我们在图表中显示数值就比较简单,不用我们计算处理。jchartlib同样支持线型图、柱状图和饼状图,而且可以自定义外观样式。另外图表可直接在 swing 中使用,可保持为 jpg 和 png 格式图片。

jchartlib的预览图

     

jchartlib的使用方法

jchartlib线形图绘制的java代码如下:

/* * jchartlib demo app for a linechart * @author silvio schneider / import com.bitagentur.chart.jchartliblinechart; import com.bitagentur.data.jchartlibdataset; import com.bitagentur.data.jchartlibserie; import com.bitagentur.renderer.jchartlibpanel; import java.awt.event.windowevent; import java.awt.event.windowlistener; import javax.swing.jframe; /* * a simple demonstration application showing how to create a line chart / public class jchartlibapp extends jframe implements windowlistener { /**  * creates a new application frame  */ public jchartlibapp() {     super("jchartlib demo appllication");     final jchartlibdataset dataset = createdataset();     final jchartlibbasechart chart = createchart(dataset);     final jchartlibpanel chartpanel = new jchartlibpanel(chart);     chartpanel.setpreferredsize(new java.awt.dimension(500, 270));     setcontentpane(chartpanel); }  /**  * creates a sample dataset.  *   * @return a sample dataset.  */ private jchartlibdataset createdataset() {     //dataseries can be added with int arrays     int[] values1 = new int[5];     values1[0] = 1;     values1[1] = 3;     values1[2] = 4;     values1[3] = 7;     values1[4] = 2;      //or by generating a dataserie object     jchartlibserie values2 = new jchartlibserie("banana");     values2.addvalue(5);     values2.addvalue(4);     values2.addvalue(2);     values2.addvalue(6);     values2.addvalue(2);      final jchartlibdataset dataset = new jchartlibdataset();     dataset.adddataserie("apple", values1);   //adds the apples     dataset.adddataserie(values2);            //adds the bananas      return dataset; }  /**  * creates a chart  *   * @param dataset the data for the chart.  * @return a new chart  */ private jchartlibbasechart createchart(final jchartlibdataset dataset) {      // create the chart with title and axis names     final jchartliblinechart chart = new jchartliblinechart(             "fruits are good", // chart title             "time goes by", // x axis text             "number of fruits", // y axis text             dataset, // data             true // legend on             );      return chart; }  /**  * main method - demo application for jchartlib  *  * @param args the command line arguments  */ public static void main(final string[] args) {     system.out.println("jchartlibapp started");     final jchartlibapp app = new jchartlibapp();     app.addwindowlistener(app);     app.pack();     app.setvisible(true); }  @override public void windowopened(windowevent e) {     //nothing to do }  @override public void windowclosing(windowevent e) {     //exit and goodby     if (e.getwindow() == this) {         dispose();         system.out.println("thanks for using the jchartlibapp");         system.exit(0);     } }  @override public void windowclosed(windowevent e) {     //nothing to do  }  @override public void windowiconified(windowevent e) {     //nothing to do }  @override public void windowdeiconified(windowevent e) {     //nothing to do }  @override public void windowactivated(windowevent e) {     //nothing to do }  @override public void windowdeactivated(windowevent e) {     //nothing to do } }

jchartlib柱形图绘制的java代码如下:

/* * jchartlib demo app for a barchart * @author silvio schneider / import com.bitagentur.chart.jchartlibbarchart; import com.bitagentur.data.jchartlibdataset; import com.bitagentur.data.jchartlibserie; import com.bitagentur.renderer.jchartlibpanel; import java.awt.event.windowevent; import java.awt.event.windowlistener; import javax.swing.jframe; /* * a simple demonstration application showing how to create a bar chart / public class jchartlibapp extends jframe implements windowlistener { /**  * creates a new application frame  */ public jchartlibapp() {     super("jchartlib demo appllication");     final jchartlibdataset dataset = createdataset();     final jchartlibbarchart chart = createchart(dataset);     final jchartlibpanel chartpanel = new jchartlibpanel(chart);     chartpanel.setpreferredsize(new java.awt.dimension(500, 270));     setcontentpane(chartpanel); }  /**  * creates a sample dataset.  *   * @return a sample dataset.  */ private jchartlibdataset createdataset() {     //dataseries can be added with int arrays     int[] values1 = new int[5];     values1[0] = 1;     values1[1] = 3;     values1[2] = 4;     values1[3] = 7;     values1[4] = 2;      //or by generating a dataserie object     jchartlibserie values2 = new jchartlibserie("banana");     values2.addvalue(5);     values2.addvalue(4);     values2.addvalue(2);     values2.addvalue(6);     values2.addvalue(2);      final jchartlibdataset dataset = new jchartlibdataset();     dataset.adddataserie("apple", values1);   //adds the apples     dataset.adddataserie(values2);            //adds the bananas      return dataset; }  /**  * creates a chart  *   * @param dataset the data for the chart.  * @return a new chart  */ private jchartlibbasechart createchart(final jchartlibdataset dataset) {      // create the chart with title and axis names     final jchartlibbarchart chart = new jchartlibbarchart(             "fruits are good", // chart title             "time goes by", // x axis text             "number of fruits", // y axis text             dataset, // data             true // legend on             );      return chart; }  /**  * main method - demo application for jchartlib  *  * @param args the command line arguments  */ public static void main(final string[] args) {     system.out.println("jchartlibapp started");     final jchartlibapp app = new jchartlibapp();     app.addwindowlistener(app);     app.pack();     app.setvisible(true); }  @override public void windowopened(windowevent e) {     //nothing to do }  @override public void windowclosing(windowevent e) {     //exit and goodby     if (e.getwindow() == this) {         dispose();         system.out.println("thanks for using the jchartlibapp");         system.exit(0);     } }  @override public void windowclosed(windowevent e) {     //nothing to do  }  @override public void windowiconified(windowevent e) {     //nothing to do }  @override public void windowdeiconified(windowevent e) {     //nothing to do }  @override public void windowactivated(windowevent e) {     //nothing to do }  @override public void windowdeactivated(windowevent e) {     //nothing to do } }

jchartlib饼状图绘制的java代码如下:

/* * jchartlib demo app for a piechart * @author silvio schneider / import com.bitagentur.chart.jchartlibpiechart; import com.bitagentur.data.jchartlibdataset; import com.bitagentur.data.jchartlibserie; import com.bitagentur.renderer.jchartlibpanel; import java.awt.event.windowevent; import java.awt.event.windowlistener; import java.util.random; import javax.swing.jframe; / * a simple demonstration application showing how to create a pie chart.  / public class jchartlibapp_piechart extends jframe implements windowlistener { /**  * creates a new application frame  */ public jchartlibapp_piechart() {     super("jchartlib demo appllication");      final jchartlibdataset dataset = createdataset();     final jchartlibpiechart chart = createchart(dataset);     final jchartlibpanel chartpanel = new jchartlibpanel(chart);     chartpanel.setpreferredsize(new java.awt.dimension(500, 270));     setcontentpane(chartpanel); }  /**  * creates a sample dataset.  *   * @return a sample dataset.  */ private jchartlibdataset createdataset() {     //or by generating a dataserie object     jchartlibserie values1 = new jchartlibserie("fruits");     values1.addvalue("apple", 1);     values1.addvalue("banana", 1);     values1.addvalue("orange", 1);     values1.addvalue("tomato", 1);      final jchartlibdataset dataset = new jchartlibdataset();     dataset.adddataserie(values1);          //adds the apples      return dataset; }  /**  * creates a chart  *   * @param dataset the data for the chart.  * @return a new chart  */ private jchartlibpiechart createchart(final jchartlibdataset dataset) {      // create the chart with title and axis names     final jchartlibpiechart chart = new jchartlibpiechart(             "yammi fruitpie", // chart title             "", // x axis text             "", // y axis text             dataset // data             );      return chart; }  /**  * main method - demo application for jchartlib  *  * @param args the command line arguments  */ public static void main(final string[] args) {     system.out.println("jchartlibapp started");     final jchartlibapp_piechart app = new jchartlibapp_piechart();     app.addwindowlistener(app);     app.pack();     app.setvisible(true); }  @override public void windowopened(windowevent e) {     //nothing to do }  @override public void windowclosing(windowevent e) {     //exit and goodby     if (e.getwindow() == this) {         dispose();         system.out.println("thanks for using the jchartlibapp");         system.exit(0);     } }  @override public void windowclosed(windowevent e) {     //nothing to do }  @override public void windowiconified(windowevent e) {     //nothing to do }  @override public void windowdeiconified(windowevent e) {     //nothing to do }  @override public void windowactivated(windowevent e) {     //nothing to do }  @override public void windowdeactivated(windowevent e) {     //nothing to do } }

jchartlib的功能介绍就到这里,如有疑问,可以访问文末的官方网站,或者留言讨论。

本文链接:http://www.codeceo.com/article/java-jchartlib.html
本文作者:码农网 – 小峰
原创作品,转载必须在正文中标注并保留原文链接和作者等信息。]

展开全文
内容来源于互联网和用户投稿,文章中一旦含有亚博电竞手机版的联系方式务必识别真假,本站仅做信息展示不承担任何相关责任,如有侵权或涉及法律问题请联系亚博电竞手机版删除

最新文章

网站地图