原創(chuàng)|使用教程|編輯:鄭恭琳|2016-05-27 12:58:25.000|閱讀 1049 次
概述:本文主要給大家介紹如何使用ChartDirector創(chuàng)建單獨(dú)的Java應(yīng)用,附有最新版免費(fèi)下載和完整代碼。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
本文主要給大家介紹如何使用ChartDirector創(chuàng)建單獨(dú)的Java應(yīng)用。在創(chuàng)建程序之前看是否已經(jīng)下載了該控件,并且配置好了相應(yīng)的Java IDE開(kāi)發(fā)環(huán)境。使用ChartDirector控件創(chuàng)建圖表相對(duì)簡(jiǎn)單,控件提供了完善的API以及事例和幫助文檔,開(kāi)發(fā)人員可以輕松上手。
這里我也嘗試用ChartDirector免費(fèi)版畫(huà)了一張圖表(圖右),只是在圖表下方會(huì)出現(xiàn)一根黃條,有礙美觀,不建議使用。
在利用該控件創(chuàng)建Java圖表應(yīng)用程序之前,應(yīng)該大致了解該控件創(chuàng)建圖表的大致過(guò)程以及使用到的相關(guān)函數(shù),我們大致介紹下該事例中將要使用到的API:
完整的代碼如下:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import ChartDirector.*; public class simplebar implements DemoModule { //Name of demo program public String toString() { return "Simple Bar Chart (1)"; } //Number of charts produced in this demo public int getNoOfCharts() { return 1; } //Main code for creating charts public void createChart(ChartViewer viewer, int chartIndex) { // The data for the bar chart double[] data = {85, 156, 179.5, 211, 123}; // The labels for the bar chart String[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"}; // Create a XYChart object of size 250 x 250 pixels XYChart c = new XYChart(250, 250); // Set the plotarea at (30, 20) and of size 200 x 200 pixels c.setPlotArea(30, 20, 200, 200); // Add a bar chart layer using the given data c.addBarLayer(data); // Set the labels on the x axis. c.xAxis().setLabels(labels); // Output the chart viewer.setChart(c); //include tool tip for the chart viewer.setImageMap(c.getHTMLImageMap("clickable", "", "title='{xLabel}: {value} GBytes'")); } //Allow this module to run as standalone program for easy testing public static void main(String[] args) { //Instantiate an instance of this demo module DemoModule demo = new simplebar(); //Create and set up the main window JFrame frame = new JFrame(demo.toString()); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); frame.getContentPane().setBackground(Color.white); // Create the chart and put them in the content pane ChartViewer viewer = new ChartViewer(); demo.createChart(viewer, 0); frame.getContentPane().add(viewer); // Display the window frame.pack(); frame.setVisible(true); } }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)