资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java代码生成折线图 比较好用的java画折线图框架

Java绘制二维折线图

MapCalendar,Double map= new HashMapCalendar,Double();

芜湖县网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站设计等网站项目制作,到程序开发,运营维护。创新互联公司2013年开创至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司

时间和值组成的集合。

已知两个坐标轴上的数值点怎么用java做一个折线图?

import java.awt.Graphics;

import java.awt.Image;

import java.awt.Point;

import java.awt.image.BufferedImage;

import javax.swing.JFrame;

public class t3 extends JFrame {

t3()

{

this.setSize(200, 200);

this.setDefaultCloseOperation(3);

this.setVisible(true);

}

public static void main(String[] args)throws Exception{

new t3();

}

Point[] p = new Point[]{new Point(1,1),new Point(11,31),new Point(31,21),new Point(99,100)};

public void paint(Graphics g)

{

Image img = (Image)new BufferedImage(200,200,BufferedImage.SCALE_DEFAULT);

Graphics gg = img.getGraphics();

for(int i=0;ip.length-1;i++)

{

gg.drawLine(p[i].x, 200-p[i].y,p[i+1].x, 200-p[i+1].y);

}

g.drawImage(img, 0, 0, null);

}

}

java怎么生成折线图,传入月份(1,2,3)生产数量(100,200,300),然后生成一个折线图,最好是曲线图,谢

按照你的要求编写的折线图程序如下:生成的图片放在D盘根目录下,文件名是testline.png

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.ChartPanel;

import org.jfree.chart.ChartUtilities;

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 {

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());

saveAsFile(jfreechart, "D://testline.png", 500, 300);

return new ChartPanel(jfreechart);

}

// 生成图表主对象JFreeChart public static JFreeChart createChart(DefaultCategoryDataset linedataset) {

//定义图表对象

JFreeChart chart = ChartFactory.createLineChart("LineChart", // chart title

"Time", // domain axis label

"Quantity", // range axis label

linedataset, // data

PlotOrientation.VERTICAL, // orientation

true, // include legend

true, // tooltips

false // urls

);

CategoryPlot plot = chart.getCategoryPlot();

// customise the range axis...

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

rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

rangeAxis.setAutoRangeIncludesZero(true);

rangeAxis.setUpperMargin(1);

rangeAxis.setLabelAngle(Math.PI / 2.0);

return chart; }

//生成数据 public static DefaultCategoryDataset createDataset() {

DefaultCategoryDataset linedataset = new DefaultCategoryDataset();

// 各曲线名称

String series1 = "car";

// 横轴名称(列名称)

String type1 = "Jan";

String type2 = "Feb";

String type3 = "Mar";

linedataset.addValue(100, series1, type1); linedataset.addValue(200, series1, type2);

linedataset.addValue(300, series1, type3);

return linedataset; }

public static void saveAsFile(JFreeChart chart, String outputPath,

int weight, int height) {

FileOutputStream out = null;

try {

File outFile = new File(outputPath);

if (!outFile.getParentFile().exists()) {

outFile.getParentFile().mkdirs();

}

out = new FileOutputStream(outputPath);

// 保存为PNG文件

ChartUtilities.writeChartAsPNG(out, chart, 600, 350);

out.flush();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (out != null) {

try {

out.close();

} catch (IOException e) {

// do nothing

}

}

}

}

}

java怎么画图(不用jfreechat)纯手工画折线图(我么老师是狗)

你的意思是敲代码画折线图?swing,awt,swt都可以嘛。。找最基本的画图那部分。。draw line..

如何在netbeans6.8中用Java语言绘制类型于下图的折线图,要有详细代码

public class XYJFrame extends javax.swing.JFrame {

/**

* Creates new form XYJFrame

*/

public XYJFrame() {

initComponents();

iniCoordinate();

}

/**

* Netbeans 生成的代码,用于界面设计

*/

@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 坐标");

lblYCoordinate.setText("Y 坐标");

btnCalculateY.setText("计算 Y 坐标");

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() {

// 转折点 X 坐标

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

// 转折点 Y 坐标

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

}

// 计算 Y 坐标

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 画折线图

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);

}

// 生成图表主对象JFreeChart

public static JFreeChart createChart(DefaultCategoryDataset linedataset) {

// 定义图表对象

JFreeChart chart = ChartFactory.createLineChart("一季度销售曲线", //折线图名称

"时间", // 横坐标名称

"销售额(百万)", // 纵坐标名称

linedataset, // 数据

PlotOrientation.VERTICAL, // 水平显示图像

true, // include legend

true, // tooltips

false // urls

);

CategoryPlot plot = chart.getCategoryPlot();

plot.setRangeGridlinesVisible(true); //是否显示格子线

plot.setBackgroundAlpha(0.3f); //设置背景透明度

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

rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

rangeAxis.setAutoRangeIncludesZero(true);

rangeAxis.setUpperMargin(0.20);

rangeAxis.setLabelAngle(Math.PI / 2.0);

return chart;

}

// 生成数据

public static DefaultCategoryDataset createDataset() {

DefaultCategoryDataset linedataset = new DefaultCategoryDataset();

// 各曲线名称

String series1 = "冰箱";

String series2 = "彩电";

String series3 = "洗衣机";

// 横轴名称(列名称)

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;

}

}

网友分享,看看是否能帮到你


名称栏目:java代码生成折线图 比较好用的java画折线图框架
网页路径:http://www.cdkjz.cn/article/hhjioj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220