List of usage examples for org.jfree.chart.axis ValueAxis setTickLabelFont
public void setTickLabelFont(Font font)
From source file:com.rapidminer.gui.plotter.charts.MultipleSeriesChartPlotter.java
private JFreeChart createChart() { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title null, // x axis label null, // y axis label null, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls );// w ww . ja va 2s . c o m chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis)); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false); ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false); } ValueAxis xAxis = plot.getDomainAxis(); if (indexAxis > -1) { xAxis.setLabel(getDataTable().getColumnName(indexAxis)); } else { xAxis.setLabel(SERIESINDEX_LABEL); } xAxis.setAutoRange(true); xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); if (indexAxis > 0) { if (getRangeForDimension(indexAxis) != null) { xAxis.setRange(getRangeForDimension(indexAxis)); } } else { if (getRangeForName(SERIESINDEX_LABEL) != null) { xAxis.setRange(getRangeForName(SERIESINDEX_LABEL)); } } // renderer and range axis synchronized (dataTable) { int numberOfSelectedColumns = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { numberOfSelectedColumns++; } } } int columnCount = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { // YIntervalSeries series = new // YIntervalSeries(this.dataTable.getColumnName(c)); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataTable.getColumnName(c)); Iterator<DataTableRow> i = dataTable.iterator(); int index = 1; while (i.hasNext()) { DataTableRow row = i.next(); double value = row.getValue(c); if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { double indexValue = row.getValue(indexAxis); series.add(indexValue, value); } else { series.add(index++, value); } } dataset.addSeries(series); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Color color = getColorProvider().getPointColor(1.0d); if (numberOfSelectedColumns > 1) { color = getColorProvider() .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1)); } renderer.setSeriesPaint(0, color); renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesShapesVisible(0, false); NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c)); if (getRangeForDimension(c) != null) { yAxis.setRange(getRangeForDimension(c)); } else { yAxis.setAutoRange(true); yAxis.setAutoRangeStickyZero(false); yAxis.setAutoRangeIncludesZero(false); } yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); if (numberOfSelectedColumns > 1) { yAxis.setAxisLinePaint(color); yAxis.setTickMarkPaint(color); yAxis.setLabelPaint(color); yAxis.setTickLabelPaint(color); } plot.setRangeAxis(columnCount, yAxis); plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT); plot.setDataset(columnCount, dataset); plot.setRenderer(columnCount, renderer); plot.mapDatasetToRangeAxis(columnCount, columnCount); columnCount++; } } } } chart.setBackgroundPaint(Color.white); return chart; }
From source file:org.jfree.chart.demo.XYTickLabelDemo.java
/** * When a checkbox is changed ...//from w w w. j a va 2 s . com * * @param event the event. */ public void actionPerformed(final ActionEvent event) { final ValueAxis[] axes = new ValueAxis[4]; final XYPlot plot = this.chart.getXYPlot(); axes[0] = plot.getDomainAxis(); axes[1] = plot.getRangeAxis(); axes[2] = plot.getDomainAxis(1); axes[3] = plot.getRangeAxis(1); final Object source = event.getSource(); if (source == this.symbolicAxesCheckBox) { final boolean val = this.symbolicAxesCheckBox.isSelected(); for (int i = 0; i < axes.length; i++) { ValueAxis axis = axes[i]; final String label = axis.getLabel(); final int maxTick = (int) axis.getUpperBound(); final String[] tickLabels = new String[maxTick]; final Font ft = axis.getTickLabelFont(); for (int itk = 0; itk < maxTick; itk++) { tickLabels[itk] = "Label " + itk; } axis = val ? new SymbolicAxis(label, tickLabels) : new NumberAxis(label); axis.setTickLabelFont(ft); axes[i] = axis; } plot.setDomainAxis(axes[0]); plot.setRangeAxis(axes[1]); plot.setDomainAxis(1, axes[2]); plot.setRangeAxis(1, axes[3]); } if (source == this.symbolicAxesCheckBox || source == this.verticalTickLabelsCheckBox) { final boolean val = this.verticalTickLabelsCheckBox.isSelected(); for (int i = 0; i < axes.length; i++) { axes[i].setVerticalTickLabels(val); } } else if (source == this.symbolicAxesCheckBox || source == this.horizontalPlotCheckBox) { final PlotOrientation val = this.horizontalPlotCheckBox.isSelected() ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL; this.chart.getXYPlot().setOrientation(val); } else if (source == this.symbolicAxesCheckBox || source == this.fontSizeTextField) { final String s = this.fontSizeTextField.getText(); if (s.length() > 0) { final float sz = Float.parseFloat(s); for (int i = 0; i < axes.length; i++) { final ValueAxis axis = axes[i]; Font ft = axis.getTickLabelFont(); ft = ft.deriveFont(sz); axis.setTickLabelFont(ft); } } } }
From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java
@Override protected void updatePlotter() { int categoryCount = prepareData(); String maxClassesProperty = ParameterService .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT); int maxClasses = 20; try {//w w w.jav a 2 s .c o m if (maxClassesProperty != null) { maxClasses = Integer.parseInt(maxClassesProperty); } } catch (NumberFormatException e) { // LogService.getGlobal().log("Series plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.", // LogService.WARNING); LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.plotter.charts.SeriesChartPlotter.parsing_property_error"); } boolean createLegend = categoryCount > 0 && categoryCount < maxClasses; JFreeChart chart = createChart(this.dataset, createLegend); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // domain axis if (axis[INDEX] >= 0) { if (!dataTable.isNominal(axis[INDEX])) { if (dataTable.isDate(axis[INDEX]) || dataTable.isDateTime(axis[INDEX])) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[INDEX])); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); if (getRangeForDimension(axis[INDEX]) != null) { domainAxis.setRange(getRangeForDimension(axis[INDEX])); } domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); domainAxis.setVerticalTickLabels(isLabelRotating()); } } else { LinkedHashSet<String> values = new LinkedHashSet<String>(); for (DataTableRow row : dataTable) { String stringValue = dataTable.mapIndex(axis[INDEX], (int) row.getValue(axis[INDEX])); if (stringValue.length() > 40) { stringValue = stringValue.substring(0, 40); } values.add(stringValue); } ValueAxis categoryAxis = new SymbolAxis(dataTable.getColumnName(axis[INDEX]), values.toArray(new String[values.size()])); categoryAxis.setLabelFont(LABEL_FONT_BOLD); categoryAxis.setTickLabelFont(LABEL_FONT); categoryAxis.setVerticalTickLabels(isLabelRotating()); chart.getXYPlot().setDomainAxis(categoryAxis); } } // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } AbstractChartPanel panel = getPlotterPanel(); if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
From source file:org.sakaiproject.evaluation.tool.reporting.EvalLikertChartBuilder.java
@SuppressWarnings("deprecation") public JFreeChart makeLikertChart() { DefaultCategoryDataset likertDataset = new DefaultCategoryDataset(); for (int i = 0; i < responses.length; i++) { likertDataset.addValue(values[i], "Responses", responses[i]); }//ww w. j ava 2 s . c o m JFreeChart chart = ChartFactory.createBarChart(null, // "Likert Chart", // Chart title null, // "Choices", // domain axis label null, // "# of Responses", // range axis label likertDataset, PlotOrientation.HORIZONTAL, false, // show legend false, // show tooltips false // show URLs ); // Set the background colours chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); // Configure the bar colors and display BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(244, 252, 212)); renderer.setDrawBarOutline(true); renderer.setOutlinePaint(new Color(34, 35, 237)); renderer.setOutlineStroke(new BasicStroke(0.5f)); renderer.setBaseItemLabelsVisible(true); if (showPercentages) { renderer.setBaseItemLabelGenerator(new LikertPercentageItemLabelGenerator(this.responseCount)); } else { renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } // Turn off the Top Value Axis ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setVisible(false); rangeAxis.setUpperMargin(0.35); rangeAxis.resizeRange(1.1f); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setMaximumCategoryLabelWidthRatio(0.4f); domainAxis.setMaximumCategoryLabelLines(2); // Set the font for the labels Font labelFont = new Font("Serif", Font.PLAIN, 6); CategoryItemRenderer itemRenderer = plot.getRenderer(); itemRenderer.setBaseItemLabelFont(labelFont); plot.setOutlinePaint(null); domainAxis.setLabelFont(labelFont); domainAxis.setTickLabelFont(labelFont); rangeAxis.setLabelFont(labelFont); rangeAxis.setTickLabelFont(labelFont); return chart; }
From source file:com.polivoto.vistas.Charts.java
private void crearBarChart(Pregunta pregunta) { JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(Color.white); panelGrafica.add(panel);/*from w w w .j a v a 2 s .co m*/ DefaultCategoryDataset data = new DefaultCategoryDataset(); // Fuente de Datos //Calcular el nmero N de perfiles. Si N=1, no discriminar por pestanas. //Si son N perfiles (N>2), hacer N+1 pestanas (la ltima representa la //suma de los resultados sin segregacin. int n = pregunta.obtenerCantidadDePerfiles(); System.out.println(" n " + n); if (n > 1) { for (int i = 0; i < n; i++) { List<Opcion> opciones = pregunta.obtenerResultadoPorPerfil(i).getOpciones(); for (Opcion opc : opciones) { data.setValue(opc.getCantidad(), opc.getNombre(), pregunta.obtenerResultadoPorPerfil(i).getPerfil()); } } } for (int i = 0; i < pregunta.obtenerCantidadDeOpciones(); i++) { Opcion opc = pregunta.obtenerOpcion(i); data.setValue(opc.getCantidad(), opc.getNombre(), "Todos"); } // Creando el Grafico JFreeChart chart = ChartFactory.createBarChart("\n" + pregunta.getTitulo() + "\n", "Perfil", "Total de votos", data, PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? ); //chart.setBackgroundPaint(Color.white); chart.getTitle().setFont(new Font("Roboto", 0, 28)); //chart.addSubtitle(new TextTitle("Titulo jajaja")); //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white)); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setOutlineVisible(false); ChartPanel barChart = new ChartPanel(chart); barChart.setBounds(panel.getVisibleRect()); //barChart.setPreferredSize(panelGrafica.getSize()); //barChart.setBounds(panel.getVisibleRect()); //Colores de Barras Paint[] colors = { new Color(124, 181, 236), new Color(244, 91, 91), new Color(144, 237, 125), new Color(67, 67, 72), new Color(247, 163, 92), new Color(128, 133, 233), new Color(241, 92, 128), new Color(228, 211, 84), new Color(43, 144, 143), new Color(145, 232, 225) }; ((org.jfree.chart.renderer.category.BarRenderer) plot.getRenderer()) .setBarPainter(new StandardBarPainter()); // Quita Efecto luz BarRenderer renderer = new BarRenderer(colors); renderer.setColor(plot, data); //Numeros sobre barras CategoryItemRenderer renderizar; renderizar = plot.getRenderer(); renderizar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderizar.setBaseItemLabelsVisible(true); renderizar.setItemLabelFont(new Font("Roboto", 0, 18)); //Valores eje Y ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setLabelFont(new Font("Roboto", 0, 17)); rangeAxis.setTickLabelFont(new Font("Roboto", 0, 17)); //Diseo categorias org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(new Font("Roboto", 0, 17)); domainAxis.setTickLabelFont(new Font("Roboto", 0, 17)); /*domainAxis.setTickLabelPaint(new Color(160, 163, 165)); domainAxis.setCategoryLabelPositionOffset(4); domainAxis.setLowerMargin(0); domainAxis.setUpperMargin(0); domainAxis.setCategoryMargin(0.2); */ //Leyendas LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.BOTTOM); Font nwfont = new Font("Roboto", 0, 18); legend.setItemFont(nwfont); legend.setBorder(0, 0, 0, 0); legend.setBackgroundPaint(Color.WHITE); legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 15)); /* plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}")); plot.setLegendItemShape(new Rectangle(25, 25)); */ // Pintar panel.removeAll(); panel.add(barChart); panel.repaint(); panel.revalidate(); panelGrafica.repaint(); panelGrafica.revalidate(); }
From source file:ds.monte.carlo.Application.java
private void createLengthGraph(HashMap<Integer, Integer> probability) { DefaultCategoryDataset pDataset = new DefaultCategoryDataset(); for (Integer key : probability.keySet()) { pDataset.setValue(probability.get(key), "", "" + key); }//from ww w. jav a2 s . co m JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", pDataset, PlotOrientation.VERTICAL, false, false, false); growChart.setBackgroundPaint(Color.WHITE); CategoryPlot catPlot = growChart.getCategoryPlot(); catPlot.setRangeGridlinePaint(new Color(92, 184, 92)); ValueAxis vAxis = catPlot.getRangeAxis(); CategoryAxis cAxis = catPlot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); cAxis.setTickLabelsVisible(false); Font font = new Font("SansSerif", Font.PLAIN, 12); Font fontTitle = new Font("SansSerif", Font.PLAIN, 14); vAxis.setTickLabelFont(font); growChart.getTitle().setFont(fontTitle); LineAndShapeRenderer renderer = (LineAndShapeRenderer) catPlot.getRenderer(); Color bootstrapGreen = new Color(92, 184, 92); renderer.setSeriesPaint(0, bootstrapGreen); ChartPanel chartPanel = new ChartPanel(growChart); jPanel9.removeAll(); jPanel9.add(chartPanel, BorderLayout.CENTER); jPanel9.validate(); }
From source file:ds.monte.carlo.Application.java
private void createFrequencyGraph(HashMap<Long, Integer> dictionary) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); long checksum = 0; for (Long key : dictionary.keySet()) { dataset.setValue(dictionary.get(key), "", "" + key); checksum += dictionary.get(key); }// w w w . j a v a2 s.c om JFreeChart chart = ChartFactory.createBarChart("Frequency graph", "", "", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.WHITE); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(new Color(92, 184, 92)); ValueAxis vAxis = catPlot.getRangeAxis(); CategoryAxis cAxis = catPlot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); Font font = new Font("SansSerif", Font.PLAIN, 12); Font fontTitle = new Font("SansSerif", Font.PLAIN, 14); Font fontc = new Font("SansSerif", Font.PLAIN, 10); vAxis.setTickLabelFont(font); chart.getTitle().setFont(fontTitle); cAxis.setTickLabelFont(fontc); BarRenderer renderer = (BarRenderer) catPlot.getRenderer(); Color bootstrapGreen = new Color(92, 184, 92); renderer.setSeriesPaint(0, bootstrapGreen); ChartPanel chartPanel = new ChartPanel(chart); jPanel5.removeAll(); jPanel5.add(chartPanel, BorderLayout.CENTER); jPanel5.validate(); //jPanel5.setVisible(true); System.out.println("Checksum " + checksum); System.out.println("NumberOfReplications " + numberOfReplications); }
From source file:ds.monte.carlo.Application.java
private void createGrowthGraph(double[] growthMap) { DefaultCategoryDataset growthDataset = new DefaultCategoryDataset(); double min = 1000000; double max = 0; int l_100 = growthMap.length; int l_40 = (int) Math.round(l_100 * 0.4); System.out.print(growthMap.length); for (int i = l_40; i < growthMap.length; i++) { growthDataset.setValue(growthMap[i], "", "" + i); if (growthMap[i] < min) { min = growthMap[i];//from ww w.jav a 2 s .c o m } if (growthMap[i] > max) { max = growthMap[i]; } } JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", growthDataset, PlotOrientation.VERTICAL, false, false, false); growChart.setBackgroundPaint(Color.WHITE); CategoryPlot catPlot = growChart.getCategoryPlot(); catPlot.setRangeGridlinePaint(new Color(92, 184, 92)); ValueAxis vAxis = catPlot.getRangeAxis(); CategoryAxis cAxis = catPlot.getDomainAxis(); cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); vAxis.setRange(min, max); cAxis.setTickLabelsVisible(false); Font font = new Font("SansSerif", Font.PLAIN, 12); Font fontTitle = new Font("SansSerif", Font.PLAIN, 14); vAxis.setTickLabelFont(font); growChart.getTitle().setFont(fontTitle); LineAndShapeRenderer renderer = (LineAndShapeRenderer) catPlot.getRenderer(); Color bootstrapGreen = new Color(92, 184, 92); renderer.setSeriesPaint(0, bootstrapGreen); ChartPanel chartPanel = new ChartPanel(growChart); jPanel6.removeAll(); jPanel6.add(chartPanel, BorderLayout.CENTER); jPanel6.validate(); //jPanel5.setVisible(true); }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartCategoryGraphSource.java
@Override public void initialize() throws GraphException { String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE); String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL); String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL); CategoryDataset dataset = makeDataSet(); chart = createChart(title, xLabel, yLabel, dataset, false, false); // start customizing the graph Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR); Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor); Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET); Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class, backgroundColor);/*from w w w. j a v a 2s . c o m*/ Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class, backgroundColor); boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER); chart.setBackgroundPaint(backgroundColor); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(plotColor); plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset)); plot.setDomainGridlinePaint(graphDomainGridlinePaint); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(graphRangeGridlinePaint); plot.setOutlineVisible(graphBorder); // set the axis location AxisLocation axisLocation = getParam(GraphSource.GRAPH_RANGE_AXIS_LOCATION, AxisLocation.class, AxisLocation.TOP_OR_LEFT); plot.setRangeAxisLocation(axisLocation); // customize the y-axis if (params.get(RANGE_AXIS) instanceof ValueAxis) { ValueAxis valueAxis = (ValueAxis) params.get(RANGE_AXIS); plot.setRangeAxis(valueAxis); } ValueAxis valueAxis = plot.getRangeAxis(); Object yAxisFont = params.get(GraphSource.GRAPH_Y_AXIS_FONT); Object yAxisLabelFont = params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT); Double rangeLowerBound = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, null); Double rangeUpperBound = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, null); boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false); boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class, true); if (yAxisFont instanceof Font) { valueAxis.setTickLabelFont((Font) yAxisFont); } if (yAxisLabelFont instanceof Font) { valueAxis.setLabelFont((Font) yAxisLabelFont); } if (rangeLowerBound != null) { valueAxis.setLowerBound(rangeLowerBound); } if (rangeUpperBound != null) { valueAxis.setUpperBound(rangeUpperBound); } if (graphRangeIntegerTick) { valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } valueAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible); // customize the x-axis if (params.get(DOMAIN_AXIS) instanceof CategoryAxis) { CategoryAxis domainAxis = (CategoryAxis) params.get(DOMAIN_AXIS); plot.setDomainAxis(domainAxis); } CategoryAxis domainAxis = plot.getDomainAxis(); Object xAxisFont = params.get(GraphSource.GRAPH_X_AXIS_FONT); Object xAxisLabelFont = params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT); if (xAxisFont instanceof Font) { domainAxis.setTickLabelFont((Font) xAxisFont); } if (xAxisLabelFont instanceof Font) { domainAxis.setLabelFont((Font) xAxisLabelFont); } domainAxis.setLabel(xLabel); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); // change the font of the graph title Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT); TextTitle textTitle = new TextTitle(); textTitle.setText(title); textTitle.setFont(titleFont); chart.setTitle(textTitle); // makes a wrapper for the legend to remove the border around it boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND); boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER); Object legendFont = params.get(GraphSource.LEGEND_FONT); if (legend) { LegendTitle legendTitle = new LegendTitle(chart.getPlot()); BlockContainer wrapper = new BlockContainer(new BorderArrangement()); if (legendBorder) { wrapper.setFrame(new BlockBorder(1, 1, 1, 1)); } else { wrapper.setFrame(new BlockBorder(0, 0, 0, 0)); } BlockContainer items = legendTitle.getItemContainer(); items.setPadding(2, 10, 5, 2); wrapper.add(items); legendTitle.setWrapper(wrapper); legendTitle.setPosition(RectangleEdge.BOTTOM); legendTitle.setHorizontalAlignment(HorizontalAlignment.CENTER); if (legendFont instanceof Font) { legendTitle.setItemFont((Font) legendFont); } chart.addSubtitle(legendTitle); } this.initialized = true; }
From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java
/** * ?jfreechart//from www . jav a2s . co m */ public void initChart() { ts_LP = new TimeSeries("LowPressure", Millisecond.class); ts_HP = new TimeSeries("HighPressure", Millisecond.class); ts_humidity = new TimeSeries("Humidity", Millisecond.class); ts_temprature = new TimeSeries("Temperature", Millisecond.class); ts_time = new TimeSeries("TestTime", Millisecond.class); ts_num = new TimeSeries("num", Millisecond.class); ts_reserved1 = new TimeSeries("reserved1", Millisecond.class); ts_reserved2 = new TimeSeries("reserved2", Millisecond.class); ts_reserved3 = new TimeSeries("reserved3", Millisecond.class); trcollection = new TimeSeriesCollection(ts_LP); trcollection.addSeries(ts_HP); trcollection2 = new TimeSeriesCollection(ts_humidity); trcollection2.addSeries(ts_temprature); // trcollection2.addSeries(ts_num); // trcollection2.addSeries(ts_time); //trcollection2.addSeries(ts_reserved1); //trcollection2.addSeries(ts_reserved2); //trcollection2.addSeries(ts_reserved3); // timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1)); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection, true, true, false); XYPlot xyplot = jfreechart.getXYPlot(); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); Font fs = new Font("", Font.BOLD, 14); Font fs2 = new Font("", Font.BOLD, 12); XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0); Color purple = new Color(139, 0, 255); line0render.setSeriesPaint(0, Color.blue); line0render.setSeriesPaint(1, Color.green); line0render.setSeriesPaint(2, Color.red); line0render.setSeriesPaint(3, purple); // line0render.setSeriesPaint(3, Color.ORANGE); XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer(); Color Rosered = new Color(230, 28, 100); line1render.setSeriesPaint(0, Color.cyan); line1render.setSeriesPaint(1, Rosered); line1render.setSeriesPaint(2, Color.orange); line1render.setSeriesPaint(3, Color.yellow); line1render.setBaseShapesVisible(false); xyplot.setRenderer(1, line1render); //?? ValueAxis valueaxis = xyplot.getDomainAxis(); // valueaxis.setLabelFont(fs); // valueaxis.setTickLabelFont(fs2); ValueAxis valueaxis2 = new NumberAxis(""); valueaxis2.setLabelFont(fs); valueaxis2.setTickLabelFont(fs2); xyplot.setRangeAxis(1, valueaxis2); xyplot.setDataset(1, trcollection2); xyplot.mapDatasetToRangeAxis(1, 1); //?? valueaxis.setAutoRange(true); //?? 7days // valueaxis.setFixedAutoRange(604800000D); valueaxis = xyplot.getRangeAxis(); valueaxis.setLabelFont(new Font("", Font.BOLD, 14)); valueaxis.setLabelPaint(line0render.getSeriesPaint(0)); valueaxis2.setLabelPaint(line1render.getSeriesPaint(0)); jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));// jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15)); xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}", new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000"))); xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}", new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000"))); chartPanel = new ChartPanel(jfreechart); initChartMenu(); // chartPanel.getPopupMenu().add(jmenuitem2); // chartPanel.getPopupMenu().getPopupMenuListeners(); chartPanel.setSize(950, 620); chartPanel.setPreferredSize(new Dimension(950, 620)); jPanel_Show.add(chartPanel, BorderLayout.CENTER); }