在 JFreeChart 中创建方格纸背景

发布于 2025-01-18 18:13:15 字数 1784 浏览 4 评论 0 原文

我正在使用 JFreeChart 库来绘制心电图信号。我正在使用 XYLineChart,这就是它当前的样子。 输入图片描述在这里

但是,我想要一个方格纸背景,由 5x5 正方形制成,如下图所示:

mybackground.jpg

每个内部小方块都是 1mm X 1mm,因此较大的方块组成了尺寸为 5 毫米 X 5 毫米。我想要 25mm/s 和 10mm/mV 的对应关系。这就是我设置图表的方式:

//Declaration of the dataset

private XYSeriesCollection dataset = new XYSeriesCollection();

//Dataset will be populated from a txt file in another function called createDataSet

createDataSet();

//Creation of the chart:

    JFreeChart myChart = ChartFactory.createXYLineChart("ECG", "Time(ms)", "Voltage(mV)", dataset,
                PlotOrientation.VERTICAL, false, false, false);

//I am using JavaFX so I need to wrap my graph into a ChartPanel and then a SwingNode,
//and I also want the graph to be zoomable with the mousewheel so I am adding the following lines:

            mychartPanel = new ChartPanel(myChart);
            mychartPanel.setPreferredSize(new java.awt.Dimension(626, 266));
            mychartPanel.setMouseWheelEnabled(true);
            mychartPanel.setRangeZoomable(true);
            mychartPanel.setDomainZoomable(true);
            myswingnode.setContent(mychartPanel);

我尝试的是将这个图像设置为背景:

mybackground = ImageIO.read(new File("mybackground.jpg"));
myChart.getPlot().setBackgroundImage(mybackground);

但是,图像变得模糊,当我缩放时,背景是静态的(即我没有放大背景,而只是放大)进入图表的线条)。

我想问的是,是否可以根据我的喜好更改绘图的网格线,以达到所需的背景?或者您有其他建议的方法吗?

我读过这些功能 “setTickMarkOutsideLength(int n)”和“setTickMarkInsideLength(int n)”应该会影响网格线,但我在使用它们时没有看到任何变化。

I am using JFreeChart library to plot an ECG signal. I'm using the XYLineChart, and this is how it looks currently. enter image description here

However, I want to have a graph paper background, made out of 5x5 squares, like on this picture:

mybackground.jpg

Each inner small square is 1mm X 1mm, so the bigger squares make up the size of 5mm X 5mm. I want to have a correspondence of 25mm/s and 10mm/mV. This is how I set up the chart:

//Declaration of the dataset

private XYSeriesCollection dataset = new XYSeriesCollection();

//Dataset will be populated from a txt file in another function called createDataSet

createDataSet();

//Creation of the chart:

    JFreeChart myChart = ChartFactory.createXYLineChart("ECG", "Time(ms)", "Voltage(mV)", dataset,
                PlotOrientation.VERTICAL, false, false, false);

//I am using JavaFX so I need to wrap my graph into a ChartPanel and then a SwingNode,
//and I also want the graph to be zoomable with the mousewheel so I am adding the following lines:

            mychartPanel = new ChartPanel(myChart);
            mychartPanel.setPreferredSize(new java.awt.Dimension(626, 266));
            mychartPanel.setMouseWheelEnabled(true);
            mychartPanel.setRangeZoomable(true);
            mychartPanel.setDomainZoomable(true);
            myswingnode.setContent(mychartPanel);

What I have tried is to set this image as the background with:

mybackground = ImageIO.read(new File("mybackground.jpg"));
myChart.getPlot().setBackgroundImage(mybackground);

But, the image gets blurry and when I zoom, the background is static (i.e. I'm not zooming into the background but just into the lines of the graph).

What I want to ask is, is it possible to change the gridlines of the plot according to my preferences, in order to achieve the desired background? Or is there any other way you suggest?

I've read that the functions
"setTickMarkOutsideLength(int n)" and "setTickMarkInsideLength(int n)" should affect the gridlines, but I've seen no change when I used them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文