List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions
public void setCategoryLabelPositions(CategoryLabelPositions positions)
From source file:com.pureinfo.srm.reports.impl.CategoryChartBuilder.java
/** * @see com.pureinfo.srm.reports.IChartBuilder#buildChart(java.util.List, * int, java.lang.String)/*from w ww .j av a 2 s .c o m*/ */ public JFreeChart buildChart() { CategoryDataset dataset = createDataset(); JFreeChart jfreechart = MyChartFactory.createBarChart3D(null, m_sXAxisName, m_sYXxisName, dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot categoryplot = jfreechart.getCategoryPlot(); jfreechart.setBackgroundPaint(Color.white); categoryplot.setDomainGridlinesVisible(false); categoryplot.setRangeGridlinesVisible(true); categoryplot.setForegroundAlpha(0.8f); categoryplot.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); CategoryAxis categoryAxisX = categoryplot.getDomainAxis(); categoryAxisX.setTickLabelsVisible(true); categoryAxisX.setLabel(null); categoryAxisX.setMaximumCategoryLabelWidthRatio(.8f); ValueAxis categoryAxisY = categoryplot.getRangeAxis(); categoryAxisY.setVerticalTickLabels(false); // categoryplot.setDrawSharedDomainAxis(false); categoryAxisX.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D)); BarRenderer3D barrenderer3d = (BarRenderer3D) categoryplot.getRenderer(); barrenderer3d.setDrawBarOutline(false); barrenderer3d.setItemLabelsVisible(true); barrenderer3d.setBaseItemLabelsVisible(false); barrenderer3d.setSeriesVisible(Boolean.FALSE); //CategoryPlot categoryPlot = jfreechart.getCategoryPlot(); // categoryPlot.setBackgroundPaint(Color.lightGray); // categoryPlot.setDomainGridlinePaint(Color.white); // categoryPlot.setRangeGridlinePaint(Color.white); // // BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer(); // barRenderer.setDrawBarOutline(false); // barRenderer.setMaxBarWidth(0.03); // GradientPaint gradientPaint = new GradientPaint(0.0F, 0.0F, // Color.red, 0.0F, 0.0F, new Color(64, 0, 0)); // barRenderer.setSeriesPaint(0, gradientPaint); DecimalFormat format = null; if (m_dblMaxData > 1) { format = new DecimalFormat("#,###"); } else { StringBuffer sb = new StringBuffer(); sb.append("0.00#"); for (double i = m_dblMaxData; i != 0 && i < 1; i *= 10f) { sb.append("#"); } format = new DecimalFormat(sb.toString()); } fillChartInfo(dataset, format); barrenderer3d.setMaxBarWidth(8.0 / m_ChartInfo.getChartSize().x); NumberAxis numberAxis = (NumberAxis) categoryplot.getRangeAxis(0); numberAxis.setUpperMargin(0.149999999999D); numberAxis.setNumberFormatOverride(format); categoryAxisX.setCategoryLabelPositions(CategoryLabelPositions.UP_45); NumberAxis dataNumberAxis = (NumberAxis) categoryplot.getRangeAxisForDataset(0); dataNumberAxis.setUpperMargin(0.149999999999D); dataNumberAxis.setNumberFormatOverride(format); // CategoryItemRenderer renderer = categoryPlot.getRenderer(); // CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", format); // renderer.setItemLabelGenerator(generator); // renderer.setItemLabelFont(new Font("Serif", 0, 9)); // renderer.setItemLabelsVisible(true); return jfreechart; }
From source file:userInteface.Patient.ManageVitalSignsJPanel.java
private void createChart() { DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset(); int selectedRow = viewPatientsJTable.getSelectedRow(); Person person = (Person) viewPatientsJTable.getValueAt(selectedRow, 0); Patient patient = person.getPatient(); if (patient == null) { JOptionPane.showMessageDialog(this, "Patient not created, Please create Patient first.", "Error", JOptionPane.ERROR_MESSAGE); return;/*from w ww. j av a 2s . c o m*/ } ArrayList<VitalSign> vitalSignList = patient.getVitalSignHistory().getHistory(); /*At least 2 vital sign records needed to show chart */ if (vitalSignList.isEmpty() || vitalSignList.size() == 1) { JOptionPane.showMessageDialog(this, "No vital signs or only one vital sign found. At least 2 vital sign records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE); return; } for (VitalSign vitalSign : vitalSignList) { vitalSignDataset.addValue(vitalSign.getRespiratoryRate(), "RR", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getHeartRate(), "HR", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getBloodPressure(), "BP", vitalSign.getTimestamp()); vitalSignDataset.addValue(vitalSign.getWeight(), "WT", vitalSign.getTimestamp()); } JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Vital Sign Chart", "Time Stamp", "Rate", vitalSignDataset, PlotOrientation.VERTICAL, true, false, false); vitalSignChart.setBackgroundPaint(Color.white); CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot(); vitalSignChartPlot.setBackgroundPaint(Color.lightGray); CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis(); vitalSignDomainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis(); vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartFrame chartFrame = new ChartFrame("Chart", vitalSignChart); chartFrame.setVisible(true); chartFrame.setSize(500, 500); }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCategoricalCorrelationPlot.java
private void createChart() { String title = "Categorical Plot"; CategoryDataset chartData = createChartData(); CategoryAxis domainAxis = new CategoryAxis(null); NumberAxis rangeAxis = new NumberAxis(yLabel); //BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); BoxAndWhiskerCoinPlotRenderer renderer = new BoxAndWhiskerCoinPlotRenderer(); renderer.setDisplayAllOutliers(true); CategoryPlot plot = new CategoryPlot(chartData, domainAxis, rangeAxis, renderer); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(45.0 * Math.PI / 180.0)); catCorrChart = new JFreeChart(title, plot); catCorrChart.removeLegend();/*from ww w .j a v a 2 s.c om*/ //renderer.setFillBox(false); String cat = (String) chartData.getColumnKey(0); //renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset dataset, int series, int item) { String tt = ""; NumberFormat formatter = new DecimalFormat(".####"); String key = ""; //String s = formatter.format(-1234.567); // -001235 if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) { DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset; try { String med = formatter.format(ds.getMedianValue(series, item)); tt += "Median: " + med + "<br/>"; tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>"; tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>"; tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>"; tt += "Max: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item)) + "<br/>"; tt += "Min: " + formatter.format( FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item)) + "<br/>"; //tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>"; //tt += "X: " + ds.getValue(series, item).toString()+"<br/>"; //tt += "<br/><a href=\\\'#\\\' id=\\\'"+ds.getRowKeys().get(series)+"\\\' onclick=\\\'alert(this.id);return false;\\\'>"+ds.getRowKeys().get(series)+" plot</a><br/><br/>"; key = ds.getRowKeys().get(series).toString(); } catch (Exception e) { } } return tt; } }); // renderer.setToolTipGenerator(new CategoryToolTipGenerator() { // // public String generateToolTip(CategoryDataset dataset,int series, int item) { // String tt=""; // NumberFormat formatter = new DecimalFormat(".####"); // String key = ""; // //String s = formatter.format(-1234.567); // -001235 // StringBuffer sb = new StringBuffer(); // if(dataset instanceof DefaultBoxAndWhiskerCategoryDataset){ // DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset)dataset; // try { // // String str; // str = (String) ds.getColumnKey(item); // sb.append(str).append(" N="); // BoxAndWhiskerItem bwitem = ds.getItem(series,item); // // str = formatter.format(ds.getMedianValue(series, item)); // sb.append("Median: ").append(str); // str = formatter.format(ds.getMeanValue(series, item)); // sb.append(" Mean: ").append(str); // str = formatter.format(ds.getMinRegularValue(series, item)); // sb.append(" Min: ").append(str); // str = formatter.format(ds.getMaxRegularValue(series, item)); // sb.append(" Max: ").append(str); // str = formatter.format(ds.getQ1Value(series, item)); // sb.append(" Q1: ").append(str); // str = formatter.format(ds.getQ3Value(series, item)); // sb.append(" Q3: ").append(str); // // } // catch(Exception e) {} // } // // return sb.toString(); // // } // // }); plot.setNoDataMessage(null); }
From source file:it.marcoberri.mbmeteo.action.chart.GetMinOrMax.java
/** * * @param request//from w w w. java 2 s . c o m * @param response * @throws ServletException * @throws IOException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("start : " + this.getClass().getName()); final HashMap<String, String> params = getParams(request.getParameterMap()); final Integer dimy = Default.toInteger(params.get("dimy"), 600); final Integer dimx = Default.toInteger(params.get("dimx"), 800); final String from = Default.toString(params.get("from") + " 00:00:00", "1970-01-01 00:00:00"); final String to = Default.toString(params.get("to") + " 23:59:00", "2030-01-01 23:59:00"); final String field = Default.toString(params.get("field"), "outdoorTemperature"); final String period = Default.toString(params.get("period"), "day"); final String type = Default.toString(params.get("type"), "min"); request.getSession().setAttribute("from", params.get("from")); request.getSession().setAttribute("to", params.get("to")); final String cacheKey = getCacheKey(params); if (cacheReadEnable) { final Query q = ds.find(Cache.class); q.filter("cacheKey", cacheKey).filter("servletName", this.getClass().getName()); final Cache c = (Cache) q.get(); if (c == null) { log.info("cacheKey:" + cacheKey + " on servletName: " + this.getClass().getName() + " not found"); } if (c != null) { final GridFSDBFile imageForOutput = MongoConnectionHelper.getGridFS() .findOne(new ObjectId(c.getGridId())); if (imageForOutput != null) { ds.save(c); try { response.setHeader("Content-Length", "" + imageForOutput.getLength()); response.setHeader("Content-Disposition", "inline; filename=\"" + imageForOutput.getFilename() + "\""); final OutputStream out = response.getOutputStream(); final InputStream in = imageForOutput.getInputStream(); final byte[] content = new byte[(int) imageForOutput.getLength()]; in.read(content); out.write(content); in.close(); out.close(); return; } catch (Exception e) { log.error(e); } } else { log.error("file not in db"); } } } final Query q = ds.createQuery(MapReduceMinMax.class).disableValidation(); final Date dFrom = DateTimeUtil.getDate("yyyy-MM-dd hh:mm:ss", from); final Date dTo = DateTimeUtil.getDate("yyyy-MM-dd hh:mm:ss", to); final String formatIn = getFormatIn(period); final String formatOut = getFormatOut(period); final List<Date> datesIn = getRangeDate(dFrom, dTo); final HashSet<String> datesInString = new HashSet<String>(); for (Date d : datesIn) { datesInString.add(DateTimeUtil.dateFormat(formatIn, d)); } if (datesIn != null && !datesIn.isEmpty()) { q.filter("_id in", datesInString); } q.order("_id"); final List<MapReduceMinMax> mapReduceResult = q.asList(); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); ChartEnumMinMaxHelper chartEnum = ChartEnumMinMaxHelper.getByFieldAndType(field, type); for (MapReduceMinMax m : mapReduceResult) { try { final Date tmpDate = DateTimeUtil.getDate(formatIn, m.getId().toString()); if (tmpDate == null) { continue; } final Method method = m.getClass().getMethod(chartEnum.getMethod()); final Number n = (Number) method.invoke(m); dataset.addValue(n, chartEnum.getType(), DateTimeUtil.dateFormat(formatOut, tmpDate)); } catch (IllegalAccessException ex) { log.error(ex); } catch (IllegalArgumentException ex) { log.error(ex); } catch (InvocationTargetException ex) { log.error(ex); } catch (NoSuchMethodException ex) { log.error(ex); } catch (SecurityException ex) { log.error(ex); } } final JFreeChart chart = ChartFactory.createBarChart(chartEnum.getTitle(), // chart title "", // domain axis label chartEnum.getUm(), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); final CategoryPlot xyPlot = (CategoryPlot) chart.getPlot(); final CategoryAxis domain = xyPlot.getDomainAxis(); if (field.toUpperCase().indexOf("PRESSURE") != -1) { xyPlot.getRangeAxis().setRange(chartPressureMin, chartPressureMax); } else { xyPlot.getRangeAxis().setAutoRange(true); } domain.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); final File f = File.createTempFile("mbmeteo", ".jpg"); ChartUtilities.saveChartAsJPEG(f, chart, dimx, dimy); try { if (cacheWriteEnable) { final GridFSInputFile gfsFile = MongoConnectionHelper.getGridFS().createFile(f); gfsFile.setFilename(f.getName()); gfsFile.save(); final Cache c = new Cache(); c.setServletName(this.getClass().getName()); c.setCacheKey(cacheKey); c.setGridId(gfsFile.getId().toString()); ds.save(c); } response.setContentType("image/jpeg"); response.setHeader("Content-Length", "" + f.length()); response.setHeader("Content-Disposition", "inline; filename=\"" + f.getName() + "\""); final OutputStream out = response.getOutputStream(); final FileInputStream in = new FileInputStream(f.toString()); final int size = in.available(); final byte[] content = new byte[size]; in.read(content); out.write(content); in.close(); out.close(); } catch (Exception e) { log.error(e); } finally { boolean delete = f.delete(); } }
From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java
public JFreeChart createWallclockChart(String expId) { ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance(); long eid = Long.parseLong(expId); log.info("Building experiment chart for eid = " + eid); Experiment exp = edao.findExperiment(eid); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final String expName = exp.getExperimentSetup().getBasicProperties().getExperimentName(); boolean hasSuccesses = false; boolean hasFails = false; for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) { int i = 1; List<ExecutionRecordImpl> runs = new ArrayList<ExecutionRecordImpl>(batch.getRuns()); Collections.sort(runs, new RunComparator()); for (ExecutionRecordImpl exr : runs) { //log.info("Found Record... "+exr+" stages: "+exr.getStages()); if (exr != null && exr.getStages() != null) { // Look up the object, so we can get the name. DigitalObjectRefBean dh = new DataHandlerImpl().get(exr.getDigitalObjectReferenceCopy()); String dobName = "Object " + i; if (dh != null) dobName = dh.getName(); ResultsForDigitalObjectBean res = new ResultsForDigitalObjectBean( exr.getDigitalObjectReferenceCopy()); Double time = null; boolean success = false; // First, attempt to pull from stage records: // FIXME: Note that this record is really at the wrong level. /*/* w w w . j av a 2s. c om*/ if( exr.getStages().size() == 1 ) { for( ExecutionStageRecordImpl exsr : exr.getStages() ) { Double stageTime = exsr.getDoubleMeasurement( TecRegMockup.PROP_SERVICE_TIME ); if( stageTime != null ) { time = stageTime; success = exsr.isMarkedAsSuccessful(); } } } */ // Pick up from record duration: if (time == null && res.getExecutionDuration() != null) { //convert from milli seconds to seconds time = (double) res.getExecutionDuration() / 1000.0; success = res.getHasExecutionSucceededOK(); } log.info("Found DOB: {" + exr.getDigitalObjectReferenceCopy() + "} {" + dobName + "} w/ time " + time); if (res.getExecutionRecord() != null) log.info("Timing: " + res.getExecutionRecord().getStartDate() + " " + res.getExecutionRecord().getEndDate()); if (time != null) { if (success) { dataset.addValue(time, "Succeeded", dobName); hasSuccesses = true; } else { dataset.addValue(time, "Failed", dobName); hasFails = true; } } } // Increment, for the next run. i++; } } int si = dataset.getRowIndex("Succeeded"); int ri = dataset.getRowIndex("Failed"); // Create the chart. JFreeChart chart = ChartFactory.createStackedBarChart(null, "Digital Object", "Time [s]", dataset, PlotOrientation.VERTICAL, true, true, false); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); // set the range axis to display integers only... //final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); //rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); renderer.setBarPainter(new StandardBarPainter()); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0.0f, 0.9f, 0.0f)); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0.9f, 0.0f, 0.0f)); if (hasSuccesses) renderer.setSeriesPaint(si, gp0); if (hasFails) renderer.setSeriesPaint(ri, gp1); // Set the tooltips... //renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section")); renderer.setBaseToolTipGenerator(new MeasurementToolTipGenerator()); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)); // More settings chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Remove the border, as the SVG renderer has problems with the text overflowing. chart.getLegend().setBorder(0.0, 0.0, 0.0, 0.0); // Remove the padding between the axes and the plot: chart.getPlot().setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); // Set a gradient fill, fading towards the top: final GradientPaint gpb0 = new GradientPaint(0.0f, 0.0f, new Color(245, 245, 245), 0.0f, 0.0f, Color.white); chart.getPlot().setBackgroundPaint(gpb0); return chart; }
From source file:de.tsystems.mms.apm.performancesignature.PerfSigProjectAction.java
private JFreeChart createTestRunChart(final CategoryDataset dataset, final String customName) { String title = "UnitTest overview"; if (StringUtils.isNotBlank(customName)) { title = customName;/*from ww w. j a v a 2 s . c o m*/ } final JFreeChart chart = ChartFactory.createBarChart(title, // title "build", // category axis label "num", // value axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); //domainAxis.setLowerMargin(0.0); //domainAxis.setUpperMargin(0.0); //domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final StackedBarRenderer br = new StackedBarRenderer(); plot.setRenderer(br); br.setSeriesPaint(0, new Color(0xFF, 0x99, 0x99)); // degraded br.setSeriesPaint(1, ColorPalette.RED); // failed br.setSeriesPaint(2, new Color(0x00, 0xFF, 0x00)); // improved br.setSeriesPaint(3, ColorPalette.GREY); // invalidated br.setSeriesPaint(4, ColorPalette.BLUE); // passed br.setSeriesPaint(5, ColorPalette.YELLOW); // volatile return chart; }
From source file:org.jajuk.ui.views.StatView.java
/** * Collection size bars./*from w ww .ja v a 2s . c o m*/ * * @return the chart */ private ChartPanel createCollectionSize() { try { final DateFormat additionFormatter = UtilString.getAdditionDateFormatter(); CategoryDataset cdata = null; JFreeChart jfchart = null; int iMonthsNumber = 5; // number of mounts we show, mounts // before are set together in 'before' long lSizeByMonth[] = new long[iMonthsNumber + 1]; // contains size ( in Go ) for each month, first cell is before // data int[] iMonths = getMonths(iMonthsNumber); ReadOnlyIterator<Track> tracks = TrackManager.getInstance().getTracksIterator(); while (tracks.hasNext()) { Track track = tracks.next(); int i = Integer.parseInt(additionFormatter.format(track.getDiscoveryDate())) / 100; for (int j = 0; j < iMonthsNumber + 1; j++) { if (i <= iMonths[j]) { lSizeByMonth[j] += track.getTotalSize(); } } } double[][] data = new double[1][iMonthsNumber + 1]; for (int i = 0; i < iMonthsNumber + 1; i++) { data[0][i] = (double) lSizeByMonth[i] / 1073741824; } cdata = DatasetUtilities.createCategoryDataset(new String[] { "" }, getMonthsLabels(iMonthsNumber), data); // chart, use local copy of method to use better format string for // tooltips jfchart = createBarChart3D(Messages.getString("StatView.7"), // chart // title Messages.getString("StatView.8"), // domain axis label Messages.getString("StatView.9"), // range axis label cdata, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false, // urls "{1} = {2} GB"); CategoryPlot plot = jfchart.getCategoryPlot(); CategoryAxis axis = plot.getDomainAxis(); new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 8.0, CategoryLabelWidthType.CATEGORY, 0); axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); // set the background color for the chart... plot.setNoDataMessage(Messages.getString("StatView.10")); plot.setForegroundAlpha(0.5f); plot.setBackgroundAlpha(0.5f); // plot.setBackgroundImage(IconLoader.IMAGES_STAT_PAPER).getImage()); return new ChartPanel(jfchart); } catch (Exception e) { Log.error(e); return null; } }
From source file:org.jajuk.ui.views.StatView.java
/** * Track number bars.//from w w w . j a v a 2s . c om * * @return the chart */ private ChartPanel createTrackNumber() { try { final DateFormat additionFormatter = UtilString.getAdditionDateFormatter(); CategoryDataset cdata = null; JFreeChart jfchart = null; // number of months we show, mounts // before are set together in 'before' int iMonthsNumber = 5; // contains number of tracks for each month, first cell is 'before' // data int iTracksByMonth[] = new int[iMonthsNumber + 1]; int[] iMounts = getMonths(iMonthsNumber); ReadOnlyIterator<Track> tracks = TrackManager.getInstance().getTracksIterator(); while (tracks.hasNext()) { Track track = tracks.next(); int i = Integer.parseInt(additionFormatter.format(track.getDiscoveryDate())) / 100; for (int j = 0; j < iMonthsNumber + 1; j++) { if (i <= iMounts[j]) { iTracksByMonth[j]++; } } } double[][] data = new double[1][iMonthsNumber + 1]; // cannot use System.arraycopy() here because we have different types in // the arrays... // System.arraycopy(iTracksByMonth, 0, data[0], 0, iMonthsNumber); for (int i = 0; i < iMonthsNumber + 1; i++) { data[0][i] = iTracksByMonth[i]; } cdata = DatasetUtilities.createCategoryDataset(new String[] { "" }, getMonthsLabels(iMonthsNumber), data); // chart, use local copy of method to use better format string for // tooltips jfchart = createBarChart3D(Messages.getString("StatView.12"), // chart // title Messages.getString("StatView.13"), // domain axis label Messages.getString("StatView.14"), // range axis label cdata, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false, // urls "{1} = {2}"); CategoryPlot plot = jfchart.getCategoryPlot(); CategoryAxis axis = plot.getDomainAxis(); new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 8.0, CategoryLabelWidthType.CATEGORY, 0); axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); // set the background color for the chart... plot.setNoDataMessage(Messages.getString("StatView.15")); plot.setForegroundAlpha(0.5f); plot.setBackgroundAlpha(0.5f); // plot.setBackgroundImage(IconLoader.IMAGES_STAT_PAPER).getImage()); return new ChartPanel(jfchart); } catch (Exception e) { Log.error(e); return null; } }
From source file:org.martus.client.swingui.actions.ActionMenuCharts.java
private void configureBarChartPlot(JFreeChart barChart) { CategoryPlot plot = (CategoryPlot) barChart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); TickUnitSource units = NumberAxis.createIntegerTickUnits(); rangeAxis.setStandardTickUnits(units); CategoryAxis domainAxis = plot.getDomainAxis(); CategoryLabelPositions newPositions = CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0); domainAxis.setCategoryLabelPositions(newPositions); barChart.addSubtitle(new TextTitle(getLocalization().getFieldLabel("ChartSelectedBulletinsDisclaimerBar"), FontHandler.getDefaultFont(), TextTitle.DEFAULT_TEXT_PAINT, RectangleEdge.BOTTOM, TextTitle.DEFAULT_HORIZONTAL_ALIGNMENT, TextTitle.DEFAULT_VERTICAL_ALIGNMENT, TextTitle.DEFAULT_PADDING)); }
From source file:de.tsystems.mms.apm.performancesignature.PerfSigProjectAction.java
private JFreeChart createChart(final JSONObject jsonObject, final CategoryDataset dataset) throws UnsupportedEncodingException { final String measure = jsonObject.getString(Messages.PerfSigProjectAction_ReqParamMeasure()); final String chartDashlet = jsonObject.getString("chartDashlet"); final String testCase = jsonObject.getString("dashboard"); final String customMeasureName = jsonObject.getString("customName"); final String aggregation = jsonObject.getString("aggregation"); String unit = "", color = Messages.PerfSigProjectAction_DefaultColor(); for (DashboardReport dr : getLastDashboardReports()) { if (dr.getName().equals(testCase)) { final Measure m = dr.getMeasure(chartDashlet, measure); if (m != null) { unit = aggregation.equalsIgnoreCase("Count") ? "num" : m.getUnit(); color = URLDecoder.decode(m.getColor(), "UTF-8"); }/*w w w.j a va 2 s .c o m*/ break; } } String title = customMeasureName; if (StringUtils.isBlank(customMeasureName)) title = PerfSigUtils.generateTitle(measure, chartDashlet); final JFreeChart chart = ChartFactory.createBarChart(title, // title "build", // category axis label unit, // value axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend false, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); //domainAxis.setLowerMargin(0.0); //domainAxis.setUpperMargin(0.0); //domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer(); renderer.setSeriesPaint(0, Color.decode(color)); return chart; }