1 year ago
#370984
Ibrahim7
Create a graph paper background in JFreeChart
I am using JFreeChart library to plot an ECG signal. I'm using the XYLineChart, and this is how it looks currently.
However, I want to have a graph paper background, made out of 5x5 squares, like on this picture:
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.
java
javafx
jfreechart
0 Answers
Your Answer