Pessoal to com umas dificuldades em setar os valores no eixo Y de um grafico JFreeChart, configuro um formatador pra que fique com valores “Horas” HH:MM cumulativo ou seja vou ter la 26:59min… por isso nao uso tipo data…
Se alguem puder me dar uma dica de como fazer, se devo substituir o metodo do JFreeChart ou trabalhar com datas, mas como acumular datas?
Fragmento do eixo Y:
[code] DecimalFormat formatter = new DecimalFormat( hh+":"+mm+“h”);
axis2.setTickUnit(new NumberTickUnit(5, formatter));[/code]
O código completo ta o seguinte:
[code]
package jfreechart;
import java.awt.Color;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.StringTokenizer;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.Legend;
import org.jfree.chart.StandardLegend;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.time.Hour;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
/**
-
@author Ronald Tetsuo Miura - Mirante Informática
*/
public class TesteChart extends JPanel
{/**
-
@param args
*/
public static void main(String[] args)
{
Random rand = new Random();String[] categorias = new String[] { “Categoria A”, “Categoria B”, “Categoria C” };
TimeSeriesCollection dataset = new TimeSeriesCollection();
Calendar c = Calendar.getInstance();
c.clear();
for (int i = 0; i < categorias.length; i++)
{
TimeSeries series = new TimeSeries(categorias[i], Hour.class);
for (int j = 0; j < 5; j++)
{
c.set(Calendar.HOUR_OF_DAY, j);
series.add(new Hour(c.getTime()), 0 + rand.nextInt(2 + (i * j * 2)) + j * j);
}
dataset.addSeries(series);
}ValueAxis axis1 = new NumberAxis(“Eixo X”);
NumberAxis axis2 = new NumberAxis(“Eixo Y”);StandardXYItemRenderer renderer = new StandardXYItemRenderer();
XYPlot plot = new XYPlot(dataset, axis1, axis2, renderer);
axis2 = (NumberAxis) plot.getRangeAxis();
DecimalFormatSymbols simboloSeparacion = new DecimalFormatSymbols();
simboloSeparacion.setDecimalSeparator(’.’);DateFormat dateFormat = new SimpleDateFormat(“dd”);
axis2.setLowerBound(0);
axis2.setUpperBound(70);double minutos = axis2.getUpperBound();
String hh = “”;
String mm = “”;String hhmm = “” + minutos / 60;
int x = hhmm.indexOf(".",0);
for ( int a = 0; a < x; a++ )
{
hh = hh + hhmm.charAt( a );
}for ( int a = x; a < 3; a++ )
{
mm = mm + hhmm.charAt( a+1 );
}DecimalFormat formatter = new DecimalFormat( hh+":"+mm+“h”);
axis2.setTickUnit(new NumberTickUnit(5, formatter));
axis2.setTickLabelPaint(Color.gray);
StandardLegend legend = new StandardLegend();
legend.setAnchor(Legend.SOUTH);JFreeChart chart = new JFreeChart(plot);
chart.setLegend(legend);ChartPanel panel = new ChartPanel(chart);
JFrame f = new JFrame(“teste”);
f.setSize(640, 480);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(panel);
f.setVisible(true);
}
-
}[/code]