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
本文作者:碼農網 – 小峰
[ 原創作品,轉載必須在正文中標註並保留原文連結和作者等資訊。]
相關文章
- jCharts:Java圖表類庫使用介紹Java
- java集合類介紹Java
- JFreeChart:多功能Java圖表類庫Java
- java之Object類介紹JavaObject
- 基於SWT的Java圖表類庫SWTChartJava
- ECharts資料圖表使用介紹 超詳細Echarts
- http代理使用分類介紹HTTP
- Excel圖表製作方法介紹Excel
- Java併發程式設計:Thread類的使用介紹Java程式設計thread
- java ShutdownHook介紹與使用JavaHook
- PHP中 ADOdb 類庫介紹(轉)PHP
- 資料庫系列: 主流分庫分表中介軟體介紹(圖文總結)資料庫
- UML類圖介紹&類的六大關係
- 四,Java運算子詳細分類及使用方法介紹Java
- 人工智慧文生圖技術介紹人工智慧
- Java中的AI庫大全介紹JavaAI
- Java Selenide 介紹&使用JavaIDE
- java .stream(). 使用介紹 Streams APIJavaAPI
- Java中的13個原子操作類介紹Java
- 簡單介紹C#使用物件序列化類庫MessasgePackC#物件
- Google guava工具類的介紹和使用GoGuava
- gfx-rs/hal跨平臺圖形抽象庫使用介紹抽象
- 樸素貝葉斯分類流程圖介紹流程圖
- HSQL 資料庫介紹(2)--使用SQL資料庫
- MySQL表與表之間的SQL Joins圖介紹MySql
- Java介紹Java
- java.util.Arrays 快速使用介紹Java
- 基於xmpp openfire smack開發之smack類庫介紹和使用[2]Mac
- TypeScript class 類介紹TypeScript
- QTime類介紹QT
- Java版ECharts圖表庫ECharts-JavaJavaEcharts
- Java課堂 自我介紹思維導圖Java
- domutils 工具庫的使用方法介紹
- Java Base64編碼使用介紹Java
- JAVA String.format 方法使用介紹JavaORM
- Guava庫介紹Guava
- 介紹oracle外部表Oracle
- percona-toolkit效能類工具的使用介紹