大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
package com.lei.jfreechart;
皋兰ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
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;
}
}
网友分享,看看是否能帮到你
可以去官网下载它的资源包,然后根据自己想要的图,在官网找到它的js,一般的数据都是改它js里面的一段json数组,你只要在后台通过sql语句拿到数据,用json数组格式传到前台就可以了。
MapCalendar,Double map= new HashMapCalendar,Double();
时间和值组成的集合。
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
}