Red de conocimiento informático - Aprendizaje de programación - Cómo dibujar un gráfico de barras en eclipse usando código java

Cómo dibujar un gráfico de barras en eclipse usando código java

.PlotOrientation;

importar org.jfree.data.category.DefaultCategoryDataset;

/*

* Dibujar gráfico de barras

* Tú Ryo

* */

clase pública BarChart3DDemo

{

public static void main(String[] args)

{

prueba

{

/// setChartTheme

ChartFactory.setChartTheme(Theme.getTheme()); /p>

//Construyendo datos

DefaultCategoryDataset dataset = new DefaultCategoryDataset();

dataset.addValue(100, "JAVA", "1"); >

p>

dataset.addValue(200, "js", "1");

dataset.addValue(200, "JAVA", "1");

conjunto de datos .addValue(200, "js", "1");

conjunto de datos.addValue(200, "JAVA", "1")addValue(200, "C", "2"

dataset.addValue(200, "JAVA", "1")addValue(200, "C", "2"); p>

dataset.addValue(400, "CSS"); , "5");

/*

* public static JFreeChart createBarChart3D(

* título java.lang.String, establece el título del gráfico

* java.lang.String CategoryAxisLabel, establece la etiqueta del eje de categoría

* java.String valueAxisLabel, establece la etiqueta del eje de valor

* Conjunto de datos CategoryDataset, establece los datos

* dirección PlotOrientation, establece la dirección del dibujo

* leyenda booleana, establece si se mostrará la leyenda

* información sobre herramientas booleanas, establece si generar herramientas de punto de acceso

* URL booleanas) establecer si se muestra la URL

*/

JFreeChart chart = ChartFactory.createBarChart3D("Estadísticas del lenguaje de programación", " Idioma",

"Número de alumnos", conjunto de datos, PlotOrientation.VERTICAL, verdadero, falso,

falso);

//Guardar gráfico

ChartUtilities.saveChartAsPNG(nuevo archivo("E:/chart/BarChart3D.png"), gráfico, 800, 500);

S

system.out.println("Dibujo completo");

}

catch (IOException e)

{

e.printStackTrace ();

}

}

}

}

======== ===================================== ============= =========================

// Una línea un poco Hay números

paquete Prueba ;

importar java.chart.title.TextTitle;

importar org.jfree.data.time.Month

importar org.jfree.data.time; .Time.TimeSeries;

importar org.add(nuevo mes(12, 2009),

lineDataset.addSeries(timeSeries

JFreeChart); chart = ChartFactory.createTimeSeriesChart("", "date", "bmi", lineDataset, true, true, true);

//Agregar título

chart.setTitle(new TextTitle ("Índice XXXBMI", nueva fuente ("Clerical", Font.ITALIC, 15));

chart.setAntiAlias(true);

XYPlot plot = (XYPlot) gráfico. getPlot();

plot.setAxisOffset(new TriangleInsets(10, 10, 10, 10)); //La distancia entre el área de la imagen y el eje

plot.setOutlinePaint( Color.PINK );

plot.setInsets(new TriangleInsets(15, 15, 15, 15)); //La distancia entre el eje de coordenadas y la extensión más externa

// plot.setOrientation(PlotOrientation. HORIZONTAL); // La dirección del gráfico, incluido el eje de coordenadas.

AxisSpace as = new AxisSpace();

as.setLeft(25);

as.setRight(25); plot.setFixedRangeAxisSpace(as);

chart.setPadding(new TriangleInsets(5, 5, 5, 5));

chart.setNotify(true); p>//Establece si la curva muestra puntos de datos

XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));

xyitem. setBaseItemLabelFont (new Font("Dialog", 1, 14));

plot.setRenderer(xyitem);

//Display

ChartFrame frame = new ChartFrame ("try1", gráfico);

frame.pack();

frame.setVisible (verdadero);

}

}

}

}