I'm working with the JfreeChart library in java and I'm doing the graphs for the ordering methods, but I want the exchanges to be shown in execution time, what has occurred to me is that in each exchange the graph is updated but at the end of the code the graph does not show me correctly ordered values within it. However, I thought for a moment that what was wrong was the bubble method but it is not, the method orders correctly. Any solution?.
example image: image
Here the code that I have made:
private void graficar(int vector[]) {
DefaultCategoryDataset datos = new DefaultCategoryDataset();
JFreeChart chart = null;
for (int i = 0; i < vector.length; i++) {
datos.addValue(vector[i], "", "" + vector[i]);
//Crear el gráfico...
}
chart = ChartFactory.createBarChart("Metodo " + cbMetodo.getSelectedItem().toString(),
"",
"",
datos,
PlotOrientation.VERTICAL,
true,
true,
true);
//crear y visualizar en el panel
ChartPanel panel = new ChartPanel(chart);
panelGrafica.setLayout(new java.awt.BorderLayout());
panelGrafica.add(panel);
panelGrafica.validate();
}
private void burbuja() {
for (int x = 0; x < vector.length; x++) {
for (int i = 0; i < vector.length - x - 1; i++) {
if (vector[i] > vector[i + 1]) {
int tmp = vector[i + 1];
vector[i + 1] = vector[i];
vector[i] = tmp;
graficar(vector);
}
}
}
}