List of usage examples for org.jfree.chart JFreeChart getLegend
public LegendTitle getLegend()
From source file:org.cyberoam.iview.charts.CustomToolTipGeneratorForDiskUsage.java
/** * This method generates JFreeChart instance for 3D Pie chart with iView customization. * @param reportID specifies that for which report Chart is being prepared. * @param rsw specifies data set which would be used for the Chart * @param requeest used for Hyperlink generation from uri. * @return jfreechart instance with iView Customization. *//*from ww w . ja va 2 s . c om*/ public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { boolean xFlag = false; ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; try { ReportColumnBean reportColumnBean, reportColumnBeanX = null; GraphBean graphBean = null; DataLinkBean dataLinkBean = null; DefaultPieDataset dataset = new DefaultPieDataset(); graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getXColumnId());//getting ReportColumnBean For X Axis // String xColumnDBname = reportColumnBeanX.getDbColumnName(); if (reportColumnBeanX.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getZColumnId()); rsw.beforeFirst(); reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnName = reportColumnBean.getColumnName(); if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } String xData = null; while (rsw.next()) { xData = rsw.getString(reportColumnBeanX.getDbColumnName()); if (xData == null || "".equalsIgnoreCase(xData) || "null".equalsIgnoreCase(xData)) { xData = "N/A"; } else if (reportColumnBeanX.getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING && xData.indexOf(':') != -1) { String data = data = ProtocolBean.getProtocolNameById(Integer.parseInt( rsw.getString(reportColumnBeanX.getDbColumnName()).substring(0, xData.indexOf(':')))); xData = data + rsw.getString(reportColumnBeanX.getDbColumnName()).substring(xData.indexOf(':'), xData.length()); } dataset.setValue(xData, new Long(rsw.getLong(reportColumnBean.getDbColumnName()))); } chart = ChartFactory.createPieChart3D("", // chart title dataset, // data true, // include legend true, // tooltips? false // URLs? ); /* *Setting additional customization to the chart. */ //Set the background color for the chart... chart.setBackgroundPaint(Color.white); //Get a reference to the plot for further customisation... PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setBackgroundAlpha(0.0f); plot.setSectionOutlinesVisible(false); plot.setOutlineVisible(false); plot.setStartAngle(290); plot.setDepthFactor(0.1); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage("No data to display"); plot.setSectionOutlinesVisible(false); plot.setSectionOutlinePaint(Color.white); plot.setOutlineVisible(false); plot.setExplodePercent(dataset.getKey(0), 0.3); plot.setLabelLinkPaint(Color.gray); plot.setLabelBackgroundPaint(Color.white); plot.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10)); plot.setLabelOutlinePaint(Color.white); plot.setLabelShadowPaint(Color.white); LegendTitle legend = chart.getLegend(); legend.setItemFont(new Font("Arial", Font.CENTER_BASELINE, 10)); legend.setMargin(0, 0, 2, 0); legend.setHorizontalAlignment(HorizontalAlignment.CENTER); plot.setToolTipGenerator(new CustomToolTipGeneratorForPie3D("{0}: ({1} " + yColumnName + ", {2})")); //Setting Color try { plot.setSectionPaint(dataset.getKey(0), new Color(0, 0, 254)); plot.setSectionPaint(dataset.getKey(1), new Color(255, 0, 254)); plot.setSectionPaint(dataset.getKey(2), new Color(176, 176, 255)); plot.setSectionPaint(dataset.getKey(3), new Color(255, 170, 255)); plot.setSectionPaint(dataset.getKey(4), new Color(69, 153, 204)); } catch (Exception e) { } } catch (Exception e) { CyberoamLogger.appLog.debug("Pie3D.e:" + e, e); } return chart; }
From source file:org.cyberoam.iview.charts.CustomToolTipGeneratorForPie3D.java
/** * This method generates JFreeChart instance for 3D Pie chart with iView customization. * @param reportID specifies that for which report Chart is being prepared. * @param rsw specifies data set which would be used for the Chart * @param requeest used for Hyperlink generation from uri. * @return jfreechart instance with iView Customization. *///from w w w. j a v a 2 s. c o m public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { boolean xFlag = false; ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; try { ReportColumnBean reportColumnBean, reportColumnBeanX = null; GraphBean graphBean = null; DataLinkBean dataLinkBean = null; DefaultPieDataset dataset = new DefaultPieDataset(); graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getXColumnId());//getting ReportColumnBean For X Axis // String xColumnDBname = reportColumnBeanX.getDbColumnName(); if (reportColumnBeanX.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getZColumnId()); rsw.beforeFirst(); reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnName = reportColumnBean.getColumnName(); if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } String xData = null; while (rsw.next()) { xData = rsw.getString(reportColumnBeanX.getDbColumnName()); if (xData == null || "".equalsIgnoreCase(xData) || "null".equalsIgnoreCase(xData)) { xData = "N/A"; } else if (reportColumnBeanX.getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING && xData.indexOf(':') != -1) { String data = data = ProtocolBean.getProtocolNameById(Integer.parseInt( rsw.getString(reportColumnBeanX.getDbColumnName()).substring(0, xData.indexOf(':')))); xData = data + rsw.getString(reportColumnBeanX.getDbColumnName()).substring(xData.indexOf(':'), xData.length()); } dataset.setValue(xData, new Long(rsw.getLong(reportColumnBean.getDbColumnName()))); } chart = ChartFactory.createPieChart3D("", // chart title dataset, // data true, // include legend true, // tooltips? false // URLs? ); /* *Setting additional customization to the chart. */ //Set the background color for the chart... chart.setBackgroundPaint(Color.white); //Get a reference to the plot for further customisation... PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setBackgroundAlpha(0.0f); plot.setSectionOutlinesVisible(false); plot.setOutlineVisible(false); plot.setStartAngle(290); plot.setDepthFactor(0.1); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage("No data to display"); plot.setSectionOutlinesVisible(false); plot.setSectionOutlinePaint(Color.white); plot.setOutlineVisible(false); plot.setExplodePercent(dataset.getKey(0), 0.3); plot.setLabelLinkPaint(Color.gray); plot.setLabelBackgroundPaint(Color.white); plot.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10)); plot.setLabelOutlinePaint(Color.white); plot.setLabelShadowPaint(Color.white); LegendTitle legend = chart.getLegend(); legend.setItemFont(new Font("Arial", Font.CENTER_BASELINE, 10)); legend.setMargin(0, 0, 2, 0); legend.setHorizontalAlignment(HorizontalAlignment.CENTER); plot.setToolTipGenerator(new CustomToolTipGeneratorForPie3D("{0}: ({1} " + yColumnName + ", {2})")); //Setting Color try { plot.setSectionPaint(dataset.getKey(0), Pie3D.pieSections[0]); plot.setSectionPaint(dataset.getKey(1), Pie3D.pieSections[1]); plot.setSectionPaint(dataset.getKey(2), Pie3D.pieSections[2]); plot.setSectionPaint(dataset.getKey(3), Pie3D.pieSections[3]); plot.setSectionPaint(dataset.getKey(4), Pie3D.pieSections[4]); } catch (Exception e) { } } catch (Exception e) { CyberoamLogger.appLog.debug("Pie3D.e:" + e, e); } return chart; }
From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java
/** * ?jfreechart/* w w w. ja va2 s .c o 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); }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *//*from ww w. j a v a2 s. c o m*/ protected void configureChart(JFreeChart jfreeChart) throws JRException { if (getChart().getModeValue() == ModeEnum.OPAQUE) { jfreeChart.setBackgroundPaint(getChart().getBackcolor()); } else { jfreeChart.setBackgroundPaint(null); } RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP); if (jfreeChart.getTitle() != null) { TextTitle title = jfreeChart.getTitle(); title.setPaint(getChart().getTitleColor()); title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale())); title.setPosition(titleEdge); } String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); subtitle.setPaint(getChart().getSubtitleColor()); subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale())); subtitle.setPosition(titleEdge); jfreeChart.addSubtitle(subtitle); } // Apply all of the legend formatting options LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { legend.setItemPaint(getChart().getLegendColor()); if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless { legend.setBackgroundPaint(null); } else { legend.setBackgroundPaint(getChart().getLegendBackgroundColor()); } legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale())); legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM)); } configurePlot(jfreeChart.getPlot()); }
From source file:org.webcat.grader.graphs.StackedAreaChart.java
@Override protected JFreeChart generateChart(WCChartTheme chartTheme) { JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, xAxisLabel(), yAxisLabel(), tableXYDataset(), orientation(), true, false, false); XYPlot plot = chart.getXYPlot();/* w w w. ja va 2 s . c om*/ long diff = (long) tableXYDataset().getXValue(0, tableXYDataset().getItemCount() - 1) - (long) tableXYDataset().getXValue(0, 0); GregorianCalendar calDiff = new GregorianCalendar(); calDiff.setTime(new NSTimestamp(diff)); // Set the time axis PeriodAxis axis = new PeriodAxis(null); // ( "Date" ); PeriodAxisLabelInfo labelinfo[] = new PeriodAxisLabelInfo[2]; if (calDiff.get(Calendar.DAY_OF_YEAR) > 1) { axis.setTimeZone(TimeZone.getTimeZone(user().timeZoneName())); axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class); axis.setMajorTickTimePeriodClass(org.jfree.data.time.Week.class); labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); } else { axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Hour.class); labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("ha"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM-d"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); } axis.setLabelInfo(labelinfo); plot.setDomainAxis(axis); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); NumberTickUnit tickUnit = new NumberTickUnit(5); rangeAxis.setTickUnit(tickUnit); XYAreaRenderer2 renderer = (XYAreaRenderer2) plot.getRenderer(); renderer.setOutline(true); renderer.setAutoPopulateSeriesOutlinePaint(true); plot.setDomainMinorGridlinesVisible(false); plot.setRangeMinorGridlinesVisible(false); if (markValue != null) { plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairValue(markValue.doubleValue()); plot.setDomainCrosshairPaint(Color.red); plot.setDomainCrosshairStroke(MARKER_STROKE); } chart.getLegend().setBorder(0, 0, 0, 0); return chart; }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
/** * Create a chart-object using dataset object. This method takes a dataset object, e.g. a DialWidgetDefinition, * and creates and returns a JFreeChart object from it. * //from w w w.j a v a2 s. co m * @param dataset * The dataset * @param title * The title of the chart * @param units * The units of the chart value * @param width * The width of the image to create * @param height * The height of the image to create * @param logger * The logger to log any messages to * * @return JFreeChart the generated chart object */ public static JFreeChart getChart(final Dataset dataset, final String title, final String units, final int width, final int height, final ILogger logger) { JFreeChart chart = null; if (dataset instanceof DialWidgetDefinition) { chart = JFreeChartEngine.createDial((DialWidgetDefinition) dataset, title, units); } else if (dataset instanceof TimeSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createTimeSeriesCollectionChart((TimeSeriesCollectionChartDefinition) dataset); } else if (dataset instanceof TimeTableXYDatasetChartDefinition) { chart = JFreeChartEngine.createStackedTimeSeriesChart((TimeTableXYDatasetChartDefinition) dataset); } else if (dataset instanceof XYSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createXYSeriesCollectionChart((XYSeriesCollectionChartDefinition) dataset); } else if (dataset instanceof BarLineChartDefinition) { chart = JFreeChartEngine.createBarLineChart((BarLineChartDefinition) dataset); } else if (dataset instanceof CategoryDatasetChartDefinition) { chart = JFreeChartEngine.createCategoryDatasetChart((CategoryDatasetChartDefinition) dataset); } else if (dataset instanceof PieDatasetChartDefinition) { chart = JFreeChartEngine.createPieDatasetChart((PieDatasetChartDefinition) dataset); } else if (dataset instanceof XYZSeriesCollectionChartDefinition) { chart = JFreeChartEngine.createXYZSeriesCollectionChart((XYZSeriesCollectionChartDefinition) dataset); } if (chart == null) { logger.error(Messages.getInstance().getString("ChartEngine.ERROR_0002_COULD_NOT_CREATE_CHART")); //$NON-NLS-1$ } else { // TODO implement the ability to have "ImageTitle"s for subtitles ChartDefinition chartDefinition = (ChartDefinition) dataset; Iterator iter = chartDefinition.getSubtitles().iterator(); while (iter.hasNext()) { chart.addSubtitle(new TextTitle(iter.next().toString())); } chart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint()); chart.setBackgroundImage(chartDefinition.getChartBackgroundImage()); chart.setBorderVisible(chartDefinition.isBorderVisible()); chart.setBorderPaint(chartDefinition.getBorderPaint()); if (chart.getTitle() != null) { chart.getTitle().setPosition(chartDefinition.getTitlePosition()); chart.getTitle().setFont(chartDefinition.getTitleFont()); } if (chartDefinition.getLegendFont() != null && chart.getLegend() != null) { chart.getLegend().setItemFont(chartDefinition.getLegendFont()); } if (!chartDefinition.isLegendBorderVisible() && chart.getLegend() != null) { chart.getLegend().setBorder(BlockBorder.NONE); } if (chartDefinition.getLegendPosition() != null && chart.getLegend() != null) { chart.getLegend().setPosition(chartDefinition.getLegendPosition()); } } 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);/*www. java 2 s . c o 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:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java
/** * ?jfreechart//from w ww .java 2s .c om */ public void initChart() { ts_wppm = new TimeSeries("PPM", Millisecond.class); ts_wppm_zero = new TimeSeries("PPM-Zero", Millisecond.class); ts_flux = new TimeSeries("Flux", Millisecond.class); ts_wvtr = new TimeSeries("WVTR", Millisecond.class); ts_tempcell = new TimeSeries(" Cell Temperature", Millisecond.class); ts_tempambi = new TimeSeries("Ambient Temperature", Millisecond.class); ts_status = new TimeSeries("Status", Millisecond.class); ts_fitting = new TimeSeries("fitting curve1", Millisecond.class); ts_fitting2 = new TimeSeries("fitting curve2", Millisecond.class); trcollection = new TimeSeriesCollection(ts_wppm); trcollection.addSeries(ts_wppm_zero); trcollection.addSeries(ts_wvtr); trcollection.addSeries(ts_fitting2);//ppm trcollection2 = new TimeSeriesCollection(ts_flux); trcollection2.addSeries(ts_fitting);//temp3 trcollection2.addSeries(ts_tempcell); trcollection2.addSeries(ts_tempambi); trcollection2.addSeries(ts_status); // 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.orange); line1render.setSeriesPaint(1, Color.yellow); line1render.setSeriesPaint(2, Color.cyan); line1render.setSeriesPaint(3, Rosered); 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); }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
protected void initChart(JFreeChart chart, ChartModel chartModel) { if (chartModel.getBackground() instanceof Integer) { chart.setBackgroundPaint(new Color(0x00FFFFFF & (Integer) chartModel.getBackground())); } else {//from ww w . j a v a2 s .c o m chart.setBackgroundPaint(Color.WHITE); } if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null) && (chartModel.getTitle().getText().trim().length() > 0)) { Font font = ChartUtils.getFont(chartModel.getTitle().getFontFamily(), chartModel.getTitle().getFontStyle(), chartModel.getTitle().getFontWeight(), chartModel.getTitle().getFontSize()); if (font != null) { chart.getTitle().setFont(font); } RectangleEdge rectangleEdge = RectangleEdge.TOP; if (chartModel.getTitle().getLocation() != null) { switch (chartModel.getTitle().getLocation()) { case RIGHT: rectangleEdge = RectangleEdge.BOTTOM; break; case LEFT: rectangleEdge = RectangleEdge.LEFT; break; case BOTTOM: rectangleEdge = RectangleEdge.BOTTOM; break; } } chart.getTitle().setPosition(rectangleEdge); if (RectangleEdge.isTopOrBottom(rectangleEdge)) { HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER; if (chartModel.getTitle().getAlignment() != null) { switch (chartModel.getTitle().getAlignment()) { case LEFT: horizontalAlignment = horizontalAlignment.LEFT; break; case RIGHT: horizontalAlignment = horizontalAlignment.RIGHT; break; } } chart.getTitle().setHorizontalAlignment(horizontalAlignment); } } if ((chartModel.getLegend() != null) && chartModel.getLegend().getVisible()) { Font font = ChartUtils.getFont(chartModel.getLegend().getFontFamily(), chartModel.getLegend().getFontStyle(), chartModel.getLegend().getFontWeight(), chartModel.getLegend().getFontSize()); if (font != null) { chart.getLegend().setItemFont(font); } if (!chartModel.getLegend().getBorderVisible()) { chart.getLegend().setFrame(BlockBorder.NONE); } } chart.setBorderVisible(chartModel.getBorderVisible()); if (chartModel.getBorderColor() instanceof Integer) { chart.setBorderPaint(new Color(0x00FFFFFF & (Integer) chartModel.getBorderColor())); } for (StyledText subtitle : chartModel.getSubtitles()) { if ((subtitle.getText()) != null && (subtitle.getText().trim().length() > 0)) { TextTitle textTitle = new TextTitle(subtitle.getText()); Font font = ChartUtils.getFont(subtitle.getFontFamily(), subtitle.getFontStyle(), subtitle.getFontWeight(), subtitle.getFontSize()); if (font != null) { textTitle.setFont(font); } if (subtitle.getColor() != null) { textTitle.setPaint(new Color(0x00FFFFFF & subtitle.getColor())); } if (subtitle.getBackgroundColor() != null) { textTitle.setBackgroundPaint(new Color(0x00FFFFFF & subtitle.getBackgroundColor())); } chart.addSubtitle(textTitle); } } }
From source file:com.rapidminer.gui.plotter.charts.BarChartPlotter.java
@Override public void updatePlotter() { final int categoryCount = prepareData(); SwingUtilities.invokeLater(new Runnable() { @Override/* w w w .j a v a 2s .com*/ public void run() { scrollablePlotterPanel.remove(viewScrollBar); } }); CategoryDataset usedCategoryDataSet = categoryDataSet; if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) { if (orientationIndex == ORIENTATION_TYPE_VERTICAL) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.HORIZONTAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH); } }); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.VERTICAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.EAST); } }); } this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT); viewScrollBar.setMaximum(categoryCount); viewScrollBar.setValue(0); usedCategoryDataSet = this.slidingCategoryDataSet; } else { this.slidingCategoryDataSet = null; } if (categoryCount <= MAX_CATEGORIES) { JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label usedCategoryDataSet, // data orientationIndex == ORIENTATION_TYPE_VERTICAL ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL, // orientation false, // include legend if group by column is set true, // tooltips false // URLs ); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); String domainName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null; domainAxis.setLabel(domainName); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); String rangeName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null; rangeAxis.setLabel(rangeName); // bar renderer double[] colorValues = null; if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) { colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)]; } else { colorValues = new double[categoryDataSet.getColumnCount()]; } for (int i = 0; i < colorValues.length; i++) { colorValues[i] = i; } BarRenderer renderer = new ColorizedBarRenderer(colorValues); renderer.setBarPainter(new RapidBarPainter()); renderer.setDrawBarOutline(true); int size = categoryDataSet.getRowCount(); if (size > 1) { for (int i = 0; i < size; i++) { renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1))); } } plot.setRenderer(renderer); // 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); } if (panel != null) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); scrollablePlotterPanel.add(panel, BorderLayout.CENTER); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { // LogService.getGlobal().logNote("Too many columns (" + categoryCount + // "), this chart is only able to plot up to " + MAX_CATEGORIES + // " different categories."); LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }