I recently started using JFreeChart and there is something i would like to do but i'm not sure if it's possible. My program is supposed to draw a spectrogram (a sound graph) from a wav file. So i managed to get the data from my wav file in a double arraylist and to display it in a chart. But now i would like to be able to select an area of my spectrogram (with the same tool used for zooming) without zooming and to be able to play only the selected part on my sound. But i simply can't find any way to succeed. Here is my code of my chart:
package classes;
import java.awt.Color;
import java.awt.Paint;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;
public class Chart{
JFreeChart chart;
Plot plot;
//Constructeur de la classe Chart
public Chart(double[][] bs, int channel, int framesLength, float frameRate)
{
// Création d'un XY chart
XYSeries series = new XYSeries("XYGraph");
int i=0,j=0;
float k=0;
//Ajout de tous les points du tableau de 16 bytes dans le chart
for( i=0; i <channel;i++)
{
for(j=0; j< framesLength;j++)
{
//Division des valeurs par 2^15 pour être entre 1 et -1
series.add(k, (bs[i][j]/32768));
//Echelle de X
k+=(1/frameRate);
}
}
// Ajoute la série au dataset
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
// Génération du graphe
chart = ChartFactory.createXYLineChart(
"Ajouter titre à la fonction de génération", // Titre
"Temps (s)", // Nom de l'axe X
"y-axis", // Nom de l'axe Y
dataset, // Dataset
PlotOrientation.VERTICAL, // Plot Orientation
true, // Show Legend
false, // Use tooltips
false // Configure chart to generate URLs?
);
plot= (XYPlot) chart.getPlot();
}
//Renvoie le chart
public JFreeChart getChart()
{
return chart;
}
public void color(Color c)
{
plot.setBackgroundPaint(c);
}
}
And here i'm calling the Chart class and using it:
Chart chartUn= new Chart(bs, channels , frameLength , frameRate);
chartUn.color(Color.pink);
vue.setChartPanelUn(new ChartPanel(chartUn.getChart(), false));
vue.getChartPanelUn().setRangeZoomable(false);
vue.getChartPanelUn().setMouseWheelEnabled(true);
vue.getChartPanelUn() returns a ChartPanel. Would you have an idée how to solve my problem? Thanks a lot (And sorry if my english is not always exact :/)