0

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.

Ibrahim7
  • 113
  • 2
  • 7
  • 1
    Please provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) show casing how you are trying to zoom and what you are expecting. – Sai Dandem Apr 04 '22 at 03:26
  • 1
    As suggested [here](https://stackoverflow.com/q/70407385/230513), resampling a fixed-size image will inevitably lead to such artifact. What happens when you make gridlines visible? – trashgod Apr 04 '22 at 07:43
  • @trashgod the gridlines can be visualized as usual, but they are the default gridlines. I want them to produce a square shaped grid, and also to have proportions of of 25mm/s and 10mm/mV on my axes (5 large squares for 1 second, 2 large squares for 1 mV). Do you know how can I modify the points where the gridlines are produced? – Ibrahim7 Apr 04 '22 at 11:44
  • 1
    Gridlines follow tick units; your factory uses the default units; you can change them, for [example](https://stackoverflow.com/q/14054091/230513). – trashgod Apr 06 '22 at 18:13

0 Answers0