社区
Web 开发
帖子详情
Jfreechart中画双Y坐标的折线图
harbouryan
2006-10-24 03:04:15
我需要画一个有两条折线的图表,他们需要自己独立的Y轴坐标,一个在左边,一个在右边,共用一个X轴。看了半天CategoryPlot类,始终没有解决办法。
...全文
709
3
打赏
收藏
Jfreechart中画双Y坐标的折线图
我需要画一个有两条折线的图表,他们需要自己独立的Y轴坐标,一个在左边,一个在右边,共用一个X轴。看了半天CategoryPlot类,始终没有解决办法。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yzlxy
2006-10-25
打赏
举报
回复
参看
http://www.isoftone.com/product/ichart/?tab=product_service&catalog=multyaxis
不过是.NET的
harbouryan
2006-10-25
打赏
举报
回复
没有答案,等待中
heliang69
2006-10-25
打赏
举报
回复
不知道,你有没有看过JFreeChart的例子,在他的例子,我找到一个。你也可以去找一找别的,我把代码帮你粘出来的,希望能帮助你。
代码如下:
package demo;
import java.awt.Color;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.annotations.XYPointerAnnotation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.block.*;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.CompositeTitle;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.xy.*;
import org.jfree.ui.*;
public class AnnotationDemo2 extends ApplicationFrame
{
public AnnotationDemo2(String s)
{
super(s);
setContentPane(createDemoPanel());
}
private static XYDataset createDataset1()
{
XYSeries xyseries = new XYSeries("Random Data 1");
xyseries.add(1.0D, 181.80000000000001D);
xyseries.add(2D, 167.30000000000001D);
xyseries.add(3D, 153.80000000000001D);
xyseries.add(4D, 167.59999999999999D);
xyseries.add(5D, 158.80000000000001D);
xyseries.add(6D, 148.30000000000001D);
xyseries.add(7D, 153.90000000000001D);
xyseries.add(8D, 142.69999999999999D);
xyseries.add(9D, 123.2D);
xyseries.add(10D, 131.80000000000001D);
xyseries.add(11D, 139.59999999999999D);
xyseries.add(12D, 142.90000000000001D);
xyseries.add(13D, 138.69999999999999D);
xyseries.add(14D, 137.30000000000001D);
xyseries.add(15D, 143.90000000000001D);
xyseries.add(16D, 139.80000000000001D);
xyseries.add(17D, 137D);
xyseries.add(18D, 132.80000000000001D);
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
xyseriescollection.addSeries(xyseries);
return xyseriescollection;
}
private static XYDataset createDataset2()
{
XYSeries xyseries = new XYSeries("Random Data 2");
xyseries.add(1.0D, 429.60000000000002D);
xyseries.add(2D, 323.19999999999999D);
xyseries.add(3D, 417.19999999999999D);
xyseries.add(4D, 624.10000000000002D);
xyseries.add(5D, 422.60000000000002D);
xyseries.add(6D, 619.20000000000005D);
xyseries.add(7D, 416.5D);
xyseries.add(8D, 512.70000000000005D);
xyseries.add(9D, 501.5D);
xyseries.add(10D, 306.10000000000002D);
xyseries.add(11D, 410.30000000000001D);
xyseries.add(12D, 511.69999999999999D);
xyseries.add(13D, 611D);
xyseries.add(14D, 709.60000000000002D);
xyseries.add(15D, 613.20000000000005D);
xyseries.add(16D, 711.60000000000002D);
xyseries.add(17D, 708.79999999999995D);
xyseries.add(18D, 501.60000000000002D);
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
xyseriescollection.addSeries(xyseries);
return xyseriescollection;
}
private static JFreeChart createChart()
{
XYDataset xydataset = createDataset1();
JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit", xydataset, PlotOrientation.VERTICAL, false, true, false);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
NumberAxis numberaxis = (NumberAxis)xyplot.getRangeAxis();
numberaxis.setAutoRangeIncludesZero(false);
NumberAxis numberaxis1 = new NumberAxis("Secondary");
numberaxis1.setAutoRangeIncludesZero(false);
xyplot.setRangeAxis(1, numberaxis1);
xyplot.setDataset(1, createDataset2());
xyplot.mapDatasetToRangeAxis(1, 1);
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineandshaperenderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
xylineandshaperenderer.setShapesVisible(true);
xylineandshaperenderer.setShapesFilled(true);
XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D, 167.30000000000001D, -0.78539816339744828D);
xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
xypointerannotation.setPaint(Color.red);
xypointerannotation.setArrowPaint(Color.red);
xylineandshaperenderer.addAnnotation(xypointerannotation);
XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
xylineandshaperenderer1.setSeriesPaint(0, Color.black);
xylineandshaperenderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D, 613.20000000000005D, 1.5707963267948966D);
xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER);
xylineandshaperenderer1.addAnnotation(xypointerannotation1);
xyplot.setRenderer(1, xylineandshaperenderer1);
LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
blockcontainer.add(legendtitle, RectangleEdge.LEFT);
blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
blockcontainer.add(new EmptyBlock(2000D, 0.0D));
CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
compositetitle.setPosition(RectangleEdge.BOTTOM);
jfreechart.addSubtitle(compositetitle);
return jfreechart;
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart();
return new ChartPanel(jfreechart);
}
public static void main(String args[])
{
AnnotationDemo2 annotationdemo2 = new AnnotationDemo2("Annotation Demo 2");
annotationdemo2.pack();
RefineryUtilities.centerFrameOnScreen(annotationdemo2);
annotationdemo2.setVisible(true);
}
}
JfreeChart
画
双
Y轴
折线图
NULL 博文链接:https://sunshine-java.iteye.com/blog/325794
JFreeChart
双
Y轴
折线图
实例,可以直接运行
JFreeChart
双
Y轴
折线图
实例,可以直接运行,实例类为LineChartDemo1.JAVA,有注释。 若想在web工程使用只需如下。 String filename = ServletUtilities.saveChartAsPNG(
jfreechart
, 600, 400, null, session); String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename; System.out.println(ServletUtilities.getTempFilePrefix()); System.out.println(System.getProperty("java.io.tmpdir")); System.out.println(filename); %>
记得在每次调用saveChartAsPNG 方法前都要 session.removeAttribute("
JFreeChart
_Deleter"); 用户退出系统也记得调用这个方法。 删除在tomcat/temp下生成的临时图片
JFreeChart
实时多Y轴二维折线绘图
这段代码实现了一个实时多数据系列绘图的Java Swing应用,使用了
JFreeChart
库来绘制图表。以下是对代码的详细描述: 类和构造函数 类名: RealTimeMultiPlotter 继承自 JFrame,用于创建一个窗口来显示图表。 构造函数: 接收图表标题、X轴标签、Y轴标签和可选的多个Y轴标签,并进行相应的初始化: 初始化 DefaultXYDataset 用于存储数据系列。 使用 ChartFactory.createXYLineChart 创建一个XY线图,设置图表的标题和轴标签。 设置图表的字体样式,使其在图表中更美观。 配置主
坐标
轴和副
坐标
轴,若提供了多个Y轴标签,将为每个标签创建一个新的数据集和
坐标
轴。 更新数据方法 方法 update: 用于更新图表的数据。 接收系列的键、主数据(xyData),副数据的系列键和数据。 移除旧的系列数据,并添加新的数据。 对于副
坐标
的系列,也进行相应的更新。 最后调用 repaint() 方法重绘图表。
JFreeChart
饼图,柱图,
折线图
JFreeChart
饼图,柱图,
折线图
可运行
Java
JFreeChart
后台生成
折线图
Java语言纯后台生成
折线图
,饼图,柱状图。
Web 开发
81,116
社区成员
341,730
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章