BrunoCarlo 23 de jun. de 2008
Ola,
Vc consegue isto atraves do itemLabelGenerator, segue um exemplo de codigo:
class LabelGenerator extends AbstractCategoryItemLabelGenerator
implements CategoryItemLabelGenerator {
/** The threshold. */
private double threshold;
/**
* Creates a new generator that only displays labels that are greater
* than or equal to the threshold value.
*
* @param threshold the threshold value.
*/
public LabelGenerator(double threshold) {
super("", NumberFormat.getInstance());
this.threshold = threshold;
}
/**
* Generates a label for the specified item. The label is typically a
* formatted version of the data value, but any text can be used.
*
* @param dataset the dataset (<code> null</code> not permitted).
* @param series the series index (zero-based).
* @param category the category index (zero-based).
*
* @return the label (possibly <code> null</code> ).
*/
public String generateLabel(CategoryDataset dataset,
int series,
int category) {
String result = null;
Number value = dataset.getValue(series, category);
if (value != null) {
double v = value.doubleValue();
if (v > this.threshold) {
result = value.toString(); // could apply formatting here
}
}
return result;
}
}
E vc adiciona isto no seu chart assim:
CategoryItemRenderer renderer = plot.getRenderer(); // O plot aqui é o CategoryPlot
renderer.setBaseItemLabelGenerator(new LabelGenerator(50.0));
renderer.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 20));
renderer.setBaseItemLabelsVisible(true);
Gustavo_Yu 23 de jun. de 2008
Vlw bruno, tentei implementar oq vc escreveu mas ta dando erro nessa linha
public LabelGenerator ( double threshold ) {
[ color = red ] super ( "" , NumberFormat . getInstance ()); [/ color ]
this . threshold = threshold ;
}
qual biblioteca q eu devo importar?
BrunoCarlo 23 de jun. de 2008
Aqui a gente trabalha com a versão 1.0.9 do JFreeChart, qual a versão que vc usa ae?
Gustavo_Yu 23 de jun. de 2008
o problema da biblioteca consegui resolver… aqui usamos a 1.0.9 tb…
agora rodo tranquilo, fui debugando… mas quando chega nessa linha, ele para o debug e vai pro Finally…
[color=red]renderer.setBaseItemLabelGenerator(new LabelGenerator(50.0));[/color]
BrunoCarlo 23 de jun. de 2008
Gustavo Yu:
o problema da biblioteca consegui resolver… aqui usamos a 1.0.9 tb…
agora rodo tranquilo, fui debugando… mas quando chega nessa linha, ele para o debug e vai pro Finally…
[color=red]renderer.setBaseItemLabelGenerator(new LabelGenerator(50.0));[/color]
vai pro finally??? lança alguma exception???
Gustavo_Yu 23 de jun. de 2008
Não lança cara!
Simplesmente vai pro Finally…
BrunoCarlo 23 de jun. de 2008
Muito estranho, vou tentar reproduzir aqui e ja te dou um retorno.
Gustavo_Yu 24 de jun. de 2008
Bruno, consegui cara, segue a solução:
DecimalFormat decimalformat1 = new DecimalFormat ( "##,###" );
CategoryItemRenderer renderer = new BarRenderer ();
renderer . setItemLabelGenerator ( new StandardCategoryItemLabelGenerator ( "{2}" , decimalformat1 ));
renderer . setBaseItemLabelsVisible ( true );
chart . getCategoryPlot (). setRenderer ( renderer );
vlw pela ajuda brother!
BrunoCarlo 24 de jun. de 2008
PÕ, show de bola.
Foi mal a demora… é que as coisas tão freneticas… mas boa.
Gustavo_Yu 25 de jun. de 2008
Putz, outra dúvida…
Alguém sabe como faço para setar o ângulo de inclinação das barras para gerar o efeito 3D?
Se eu fizer JFreeChart chart = ChartFactory.createBarChart3D
ele cria um gráfico de barras 3D, mas como faço para eu setar o ângulo do efeito?
Tks!
argentao 11 de ago. de 2008
Troque:
CategoryItemRenderer renderer = new BarRenderer ();
por
CategoryItemRenderer renderer = new BarRenderer3D ();