成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

java繪制折線代碼 Java畫(huà)折線圖

java 中如何繪制90度折線?

90度直角彎線其實(shí)就是兩條直線,第一條線的兩個(gè)頂點(diǎn)坐標(biāo)其實(shí)你是知道的,然后第二條線的第一個(gè)頂點(diǎn)就是你第一條線的第二個(gè)頂點(diǎn),第二條線的第二個(gè)頂點(diǎn)可以根據(jù)第一個(gè)頂點(diǎn)跟長(zhǎng)度計(jì)算出來(lái)。

10年積累的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有泉州免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

如何在netbeans6.8中用Java語(yǔ)言繪制類型于下圖的折線圖,要有詳細(xì)代碼

public?class?XYJFrame?extends?javax.swing.JFrame?{

/**

*?Creates?new?form?XYJFrame

*/

public?XYJFrame()?{

initComponents();

iniCoordinate();

}

/**

*?Netbeans?生成的代碼,用于界面設(shè)計(jì)

*/

@SuppressWarnings("unchecked")

//?editor-fold?defaultstate="collapsed"?desc="Generated?Code"??????????????????????????

private?void?initComponents()?{

lblXCoordinate?=?new?javax.swing.JLabel();

lblYCoordinate?=?new?javax.swing.JLabel();

txtXCoordinate?=?new?javax.swing.JTextField();

txtYCoordinate?=?new?javax.swing.JTextField();

btnCalculateY?=?new?javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

lblXCoordinate.setText("X?坐標(biāo)");

lblYCoordinate.setText("Y?坐標(biāo)");

btnCalculateY.setText("計(jì)算?Y?坐標(biāo)");

btnCalculateY.addActionListener(new?java.awt.event.ActionListener()?{

public?void?actionPerformed(java.awt.event.ActionEvent?evt)?{

btnCalculateYActionPerformed(evt);

}

});

javax.swing.GroupLayout?layout?=?new?javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(37,?37,?37)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(lblXCoordinate)

.addComponent(lblYCoordinate))

.addGap(29,?29,?29)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,?false)

.addComponent(txtXCoordinate)

.addComponent(txtYCoordinate,?javax.swing.GroupLayout.DEFAULT_SIZE,?165,?Short.MAX_VALUE)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,?layout.createSequentialGroup()

.addComponent(btnCalculateY)

.addGap(30,?30,?30)))

.addContainerGap(131,?Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(70,?70,?70)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(lblXCoordinate)

.addComponent(txtXCoordinate,?javax.swing.GroupLayout.PREFERRED_SIZE,?javax.swing.GroupLayout.DEFAULT_SIZE,?javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(24,?24,?24)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(lblYCoordinate)

.addComponent(txtYCoordinate,?javax.swing.GroupLayout.PREFERRED_SIZE,?javax.swing.GroupLayout.DEFAULT_SIZE,?javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(28,?28,?28)

.addComponent(btnCalculateY)

.addContainerGap(103,?Short.MAX_VALUE))

);

pack();

}//?/editor-fold???????????????????????

private?void?btnCalculateYActionPerformed(java.awt.event.ActionEvent?evt)?{??????????????????????????????????????????????

this.txtYCoordinate.setText(this.calculateY()?+?"");

}????????????????????????????????????????????

/**

*?@param?args?the?command?line?arguments

*/

public?static?void?main(String?args[])?{

/*?Set?the?Nimbus?look?and?feel?*/

//editor-fold?defaultstate="collapsed"?desc="?Look?and?feel?setting?code?(optional)?"

/*?If?Nimbus?(introduced?in?Java?SE?6)?is?not?available,?stay?with?the?default?look?and?feel.

*?For?details?see??

*/

try?{

for?(javax.swing.UIManager.LookAndFeelInfo?info?:?javax.swing.UIManager.getInstalledLookAndFeels())?{

if?("Nimbus".equals(info.getName()))?{

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

}

}

}?catch?(ClassNotFoundException?ex)?{

java.util.logging.Logger.getLogger(XYJFrame.class.getName()).log(java.util.logging.Level.SEVERE,?null,?ex);

}?catch?(InstantiationException?ex)?{

java.util.logging.Logger.getLogger(XYJFrame.class.getName()).log(java.util.logging.Level.SEVERE,?null,?ex);

}?catch?(IllegalAccessException?ex)?{

java.util.logging.Logger.getLogger(XYJFrame.class.getName()).log(java.util.logging.Level.SEVERE,?null,?ex);

}?catch?(javax.swing.UnsupportedLookAndFeelException?ex)?{

java.util.logging.Logger.getLogger(XYJFrame.class.getName()).log(java.util.logging.Level.SEVERE,?null,?ex);

}

///editor-fold

/*?Create?and?display?the?form?*/

java.awt.EventQueue.invokeLater(new?Runnable()?{

public?void?run()?{

new?XYJFrame().setVisible(true);

}

});

}

private?void?iniCoordinate()?{

//?轉(zhuǎn)折點(diǎn)?X?坐標(biāo)

dbXCoordinate?=?new?double[]?{?0,?0.1,?0.3,?0.5,?1?};

//?轉(zhuǎn)折點(diǎn)?Y?坐標(biāo)

dbYCoordinate?=?new?double[]?{?0,?0.4,?0.7,?0.85,?1?};????????

}

//?計(jì)算?Y?坐標(biāo)

private?double?calculateY()?{

double?xCoordinate?=?Double.parseDouble(this.txtXCoordinate.getText());

int?xPos?=?getXPositon(xCoordinate);

return?xPos?==?-1???-1?:?(dbYCoordinate[xPos]?*?xCoordinate)?/?dbXCoordinate[xPos];

}

//?得到輸入的?X?值位置,確定比率

private?int?getXPositon(double?xCoordinate)?{

for(int?i=0;?i??dbXCoordinate.length;?i++)?{

if(xCoordinate?=?dbXCoordinate[i])?{

return?i;

}

}

return?-1;

}

private?double[]?dbXCoordinate?=?new?double[5];

private?double[]?dbYCoordinate?=?new?double[5];

private?double[]?rate?=?new?double[5];

//?Variables?declaration?-?do?not?modify?????????????????????

private?javax.swing.JButton?btnCalculateY;

private?javax.swing.JLabel?lblXCoordinate;

private?javax.swing.JLabel?lblYCoordinate;

private?javax.swing.JTextField?txtXCoordinate;

private?javax.swing.JTextField?txtYCoordinate;

//?End?of?variables?declaration???????????????????

}

如何用java 畫(huà)折線圖

package?com.lei.jfreechart;

import?javax.swing.JPanel;

import?org.jfree.chart.ChartFactory;

import?org.jfree.chart.ChartPanel;

import?org.jfree.chart.JFreeChart;

import?org.jfree.chart.axis.NumberAxis;

import?org.jfree.chart.plot.CategoryPlot;

import?org.jfree.chart.plot.PlotOrientation;

import?org.jfree.data.category.DefaultCategoryDataset;

import?org.jfree.ui.ApplicationFrame;

import?org.jfree.ui.RefineryUtilities;

public?class?LineCharts?extends?ApplicationFrame?{

/**

*?

*/

private?static?final?long?serialVersionUID?=?1L;

public?LineCharts(String?s)?{

super(s);

setContentPane(createDemoLine());

}

public?static?void?main(String[]?args)?{

LineCharts?fjc?=?new?LineCharts("折線圖");

fjc.pack();

RefineryUtilities.centerFrameOnScreen(fjc);

fjc.setVisible(true);

}

//?生成顯示圖表的面板

public?static?JPanel?createDemoLine()?{

JFreeChart?jfreechart?=?createChart(createDataset());

return?new?ChartPanel(jfreechart);

}

//?生成圖表主對(duì)象JFreeChart

public?static?JFreeChart?createChart(DefaultCategoryDataset?linedataset)?{

//?定義圖表對(duì)象

JFreeChart?chart?=?ChartFactory.createLineChart("一季度銷售曲線",?//折線圖名稱

"時(shí)間",?//?橫坐標(biāo)名稱

"銷售額(百萬(wàn))",?//?縱坐標(biāo)名稱

linedataset,?//?數(shù)據(jù)

PlotOrientation.VERTICAL,?//?水平顯示圖像

true,?//?include?legend

true,?//?tooltips

false?//?urls

);

CategoryPlot?plot?=?chart.getCategoryPlot();

plot.setRangeGridlinesVisible(true);?//是否顯示格子線

plot.setBackgroundAlpha(0.3f);?//設(shè)置背景透明度

NumberAxis?rangeAxis?=?(NumberAxis)plot.getRangeAxis();

rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

rangeAxis.setAutoRangeIncludesZero(true);

rangeAxis.setUpperMargin(0.20);

rangeAxis.setLabelAngle(Math.PI?/?2.0);

return?chart;

}

//?生成數(shù)據(jù)

public?static?DefaultCategoryDataset?createDataset()?{

DefaultCategoryDataset?linedataset?=?new?DefaultCategoryDataset();

//?各曲線名稱

String?series1?=?"冰箱";

String?series2?=?"彩電";

String?series3?=?"洗衣機(jī)";

//?橫軸名稱(列名稱)

String?type1?=?"1月";

String?type2?=?"2月";

String?type3?=?"3月";

linedataset.addValue(0.0,?series1,?type1);

linedataset.addValue(4.2,?series1,?type2);

linedataset.addValue(3.9,?series1,?type3);

linedataset.addValue(1.0,?series2,?type1);

linedataset.addValue(5.2,?series2,?type2);

linedataset.addValue(7.9,?series2,?type3);

linedataset.addValue(2.0,?series3,?type1);

linedataset.addValue(9.2,?series3,?type2);

linedataset.addValue(8.9,?series3,?type3);

return?linedataset;

}

}

網(wǎng)友分享,看看是否能幫到你

java中用jframechart如何實(shí)現(xiàn)柱狀折線組合圖,請(qǐng)教高手,最好有個(gè)例子給我看看,謝謝??!

是jFreeChart吧?

這是Struts中結(jié)合 jFreeChart 畫(huà)3種圖,是我自己一個(gè)項(xiàng)目用到的 你自己看看吧 其中為生成List數(shù)據(jù) 我是在數(shù)據(jù)庫(kù)用取出來(lái)的 jFreeChart 的接受數(shù)據(jù)應(yīng)該是 類似于二維數(shù)組型的 這個(gè)網(wǎng)上有介紹

public String chartDB() {

if (style.equals("餅圖")) {

drawPieChart();

} else if (style.equals("垂直柱狀統(tǒng)計(jì)圖")) {

drawBarChart();

} else if (style.equals("折線統(tǒng)計(jì)圖")) {

drawLineChart();

}

return SUCCESS;

}

private void drawLineChart() {

MapString, Object session = ActionContext.getContext().getSession();

recordids = (String[]) session.get("recordids");

String[] field = new String[word.length]; // 獲得要查詢的字段

String[] rowKeys = new String[word.length]; // 各字段的中文名稱

for (int i = 0; i word.length; i++) {

field[i] = word[i].split("-")[0];

rowKeys[i] = word[i].split("-")[1];

}

StringBuffer sb = new StringBuffer("SELECT ");

for (int j = 0; j field.length; j++) {

sb.append("sum(" + field[j] + "), ");

}

sb

.append("DATE_FORMAT(bas_datestart,'%Y-%m') from disasterrecord where bas_recordid in "

+ Util.typesToString(recordids)

+ " group by DATE_FORMAT(bas_datestart,'%Y-%m')");

ListObject[] list = new SearchService().findBySql(sb.toString());

DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

String[] category = new String[list.size()];

for (int k = 0; k field.length; k++) {

for (int j = 0; j list.size(); j++) {

if(list.get(j)[field.length]==null){

category[j] = "";

}else{

category[j] = list.get(j)[field.length].toString();

}

if(list.get(j)[k] ==null){

dataSet.addValue(new Double(0), rowKeys[k], category[j]);

}else{

dataSet.addValue(new Double(list.get(j)[k].toString()),

rowKeys[k], category[j]);

}

}

}

chart = ChartFactory.createLineChart(title, xname, yname, dataSet,

PlotOrientation.VERTICAL, true, true, false);

chart.getTitle().setFont(new Font("宋體", Font.BOLD, 15));

chart.getLegend().setItemFont(new Font("黑體", Font.BOLD, 15));

CategoryPlot plot = (CategoryPlot) chart.getPlot();

CategoryAxis domainAxis = plot.getDomainAxis();

/*------設(shè)置X軸坐標(biāo)上的文字-----------*/

domainAxis.setTickLabelFont(new Font("黑體", Font.PLAIN, 11));

/*------設(shè)置X軸的標(biāo)題文字------------*/

domainAxis.setLabelFont(new Font("宋體", Font.PLAIN, 12));

NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();

/*------設(shè)置Y軸坐標(biāo)上的文字-----------*/

numberaxis.setTickLabelFont(new Font("黑體", Font.PLAIN, 12));

/*------設(shè)置Y軸的標(biāo)題文字------------*/

numberaxis.setLabelFont(new Font("黑體", Font.PLAIN, 12));

}

private void drawBarChart() {

MapString, Object session = ActionContext.getContext().getSession();

recordids = (String[]) session.get("recordids");

String[] field = new String[word.length]; // 獲得要查詢的字段

String[] rowKeys = new String[word.length]; // 各字段的中文名稱

for (int i = 0; i word.length; i++) {

field[i] = word[i].split("-")[0];

rowKeys[i] = word[i].split("-")[1];

}

StringBuffer sb = new StringBuffer("SELECT ");

if (type.equals("各地區(qū)各災(zāi)害")) {

for (int j = 0; j field.length; j++) {

sb.append("sum(" + field[j] + "), ");

}

sb

.append(" bas_cityarea from disasterrecord where bas_recordid in "

+ Util.typesToString(recordids)

+ " group by bas_cityarea");

} else {

for (int j = 0; j field.length; j++) {

sb.append("sum(" + field[j] + "), ");

}

sb

.append("Year(bas_datestart) from disasterrecord where bas_recordid in "

+ Util.typesToString(recordids)

+ " group by Year(bas_datestart)");

}

ListObject[] list = new SearchService().findBySql(sb.toString());

String[] columnKeys = new String[list.size()]; // 獲得 各地區(qū)名 或者 年份

for (int k = 0; k list.size(); k++) {

columnKeys[k] = list.get(k)[field.length].toString();

}

double[][] data = new double[rowKeys.length][columnKeys.length];

for (int m = 0; m rowKeys.length; m++) {

for (int n = 0; n columnKeys.length; n++) {

if (list.get(n)[m] == null) {

data[m][n] = new Double(0);

} else {

data[m][n] = new Double(list.get(n)[m].toString());

}

}

}

CategoryDataset dataset = DatasetUtilities.createCategoryDataset(

rowKeys, columnKeys, data);

chart = ChartFactory.createBarChart3D(title, xname, yname, dataset,

PlotOrientation.VERTICAL, true, true, false);

CategoryPlot plot = chart.getCategoryPlot();// 獲取圖表區(qū)域?qū)ο?/p>

CategoryAxis domainAxis = plot.getDomainAxis();

// 水平底部列表

domainAxis.setLabelFont(new Font("黑體", Font.BOLD, 14));

// 水平底部標(biāo)題

domainAxis.setTickLabelFont(new Font("宋體", Font.BOLD, 12));

// 垂直標(biāo)題

ValueAxis rangeAxis = plot.getRangeAxis();// 獲取柱狀

rangeAxis.setLabelFont(new Font("黑體", Font.BOLD, 15));

TextTitle textTitle = chart.getTitle();

textTitle.setFont(new Font("黑體", Font.BOLD, 15));

BarRenderer3D renderer = new BarRenderer3D();

renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

renderer.setBaseItemLabelsVisible(true);

renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

renderer.setItemLabelAnchorOffset(10D);

renderer.setItemLabelFont(new Font("宋體", Font.PLAIN, 12));

renderer.setItemLabelsVisible(true);

//設(shè)置每個(gè)地區(qū)所包含的平行柱的之間距離

//renderer.setItemMargin(0.3);

plot.setRenderer(renderer);

chart.getLegend().setItemFont(new Font("黑體", Font.BOLD, 15));

}

public void drawPieChart() {

MapString, Object session = ActionContext.getContext().getSession();

recordids = (String[]) session.get("recordids");

String sql = "";

String field[] = word[0].split("-");

if (type.equals("各地區(qū)各災(zāi)害")) {

sql = "SELECT sum("

+ field[0]

+ ") +'', bas_cityarea from disasterrecord where bas_recordid in "

+ Util.typesToString(recordids) + " group by bas_cityarea";

} else {

sql = "SELECT sum("

+ field[0]

+ ") +'', Year(bas_datestart) from disasterrecord where bas_recordid in "

+ Util.typesToString(recordids)

+ " group by Year(bas_datestart)";

}

ListObject[] list = new SearchService().findBySql(sql);

DefaultPieDataset data = new DefaultPieDataset();

for (Object[] o : list) {

if(o[0] == null){

data.setValue(o[1].toString(), new Double(0));

}

data.setValue(o[1].toString(), new Double(o[0].toString()));

}

chart = ChartFactory.createPieChart(title, data, true, true, false);

Font font = new Font("SimSun", 10, 20);

TextTitle txtTitle = null;

txtTitle = chart.getTitle();

txtTitle.setFont(font);

PiePlot pieplot = (PiePlot)chart.getPlot();

pieplot.setLabelFont(font);

chart.getLegend().setItemFont(font);

}

Java開(kāi)發(fā)jfreechart的折線圖時(shí),想要實(shí)現(xiàn)鼠標(biāo)移向每個(gè)折點(diǎn)時(shí)只顯示Y軸對(duì)應(yīng)的數(shù)值,應(yīng)該怎么做?

jfreechart只能產(chǎn)生靜態(tài)圖表,鼠標(biāo)移上去顯示的數(shù)值,實(shí)際上是靠html 的map來(lái)實(shí)現(xiàn)的,因此那個(gè)矩形框是瀏覽器顯示的,與代碼無(wú)關(guān),所以也改不了的。

至于只顯示Y軸的值,請(qǐng)從chart得到plot,然后再?gòu)膒lot得到renderer,再自定義renderer的ToolTipGenerator,從而實(shí)現(xiàn)自定義的tooltip.

如果想要更動(dòng)態(tài)的圖表,可以使用flash圖表,如fusioncharts

java折線圖數(shù)據(jù)庫(kù)

用這個(gè)插件可以實(shí)現(xiàn),只需要將你從數(shù)據(jù)庫(kù)中得到的數(shù)據(jù)封裝成xml格式的數(shù)據(jù),就可以在頁(yè)面上顯示,顯示的效果就像excel中的統(tǒng)計(jì)圖,如果需要我可以給你發(fā)一下這個(gè)插件FusionChartsFree

網(wǎng)站題目:java繪制折線代碼 Java畫(huà)折線圖
本文路徑:http://jinyejixie.com/article22/dosddcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站改版企業(yè)建站、虛擬主機(jī)、定制網(wǎng)站、云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)
西丰县| 清流县| 长丰县| 英德市| 广灵县| 武功县| 永登县| 北京市| 高碑店市| 浙江省| 西平县| 舞钢市| 射洪县| 英山县| 介休市| 临泽县| 康保县| 珲春市| 麻阳| 嫩江县| 珲春市| 历史| 白朗县| 宜兴市| 时尚| 长宁县| 阿图什市| 金华市| 民乐县| 台湾省| 响水县| 双辽市| 东安县| 勐海县| 墨脱县| 遂宁市| 米脂县| 泾川县| 革吉县| 平罗县| 乳源|