将ChartPanel添加到JPanel

编程入门 行业动态 更新时间:2024-10-28 13:22:34
本文介绍了将ChartPanel添加到JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我这里有一些不起作用的代码:

I've got some not working code here:

XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, true, true, true); ChartPanel chartpanel = new ChartPanel(chart); chartpanel.setDomainZoomable(true); jPanel4.setLayout(new BorderLayout()); jPanel4.add(chartpanel, BorderLayout.NORTH);

因此,问题在于带有图表的jPanel4不可见.当我将图表面板添加到框架中并使其可见时,它将起作用.

So the problem is that the jPanel4 with a chart is not visible. When I add my chartpanel to a frame and make it visible, it works.

有人知道我的错误吗?

Anyone knows what's my mistake?

推荐答案

这对我来说效果很好:

import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; public class Main { public static void main(String[] args) { XYSeries series = new XYSeries("asdf"); for (int i = 0; i < 100; i++) series.add(i, Math.random()); XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, true, true, true); ChartPanel chartpanel = new ChartPanel(chart); chartpanel.setDomainZoomable(true); JPanel jPanel4 = new JPanel(); jPanel4.setLayout(new BorderLayout()); jPanel4.add(chartpanel, BorderLayout.NORTH); JFrame frame = new JFrame(); frame.add(jPanel4); frame.pack(); frame.setVisible(true); } }

您能为我们提供更多代码吗?您是否将其他内容放入jPanel4?每个点(NORTH, SOUTH, WEST, EAST, CENTER)中最多只能有一个组件.您是否将面板放置在框架中?

Can you provide us with a bit more code? Do you put something else into jPanel4? There can not be more than one component in every spot (NORTH, SOUTH, WEST, EAST, CENTER). Do you put your panel into a frame?

更多推荐

将ChartPanel添加到JPanel

本文发布于:2023-08-06 03:30:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1309766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ChartPanel   JPanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!