Java Code Examples for org.jfree.chart.renderer.xy.XYLineAndShapeRenderer#setDefaultShapesVisible()

The following examples show how to use org.jfree.chart.renderer.xy.XYLineAndShapeRenderer#setDefaultShapesVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TICPlot.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public void switchDataPointsVisible() {

    Boolean dataPointsVisible = null;
    final int count = plot.getDatasetCount();
    for (int i = 0; i < count; i++) {

      if (plot.getRenderer(i) instanceof XYLineAndShapeRenderer) {

        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(i);
        if (dataPointsVisible == null) {
          dataPointsVisible = !renderer.getDefaultShapesVisible();
        }
        renderer.setDefaultShapesVisible(dataPointsVisible);
      }
    }
  }
 
Example 2
Source File: UnitStatusPage.java    From freeacs with MIT License 6 votes vote down vote up
/**
 * Gets the report chart image bytes.
 *
 * @param chartMaker the chart maker
 * @param chart the chart
 * @param width the width
 * @param height the height
 * @return the report chart image bytes
 * @throws Exception the exception
 */
public static byte[] getReportChartImageBytes(
    Chart<?> chartMaker, JFreeChart chart, int width, int height) throws Exception {
  if (chart == null && chartMaker != null) {
    chart = chartMaker.makeTimeChart(null, null, null, null);
  } else if (chart == null) {
    throw new IllegalArgumentException("Chart<?> and JFreeChart is NULL.");
  }
  if (chart.getPlot() instanceof XYPlot) {
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setDefaultShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setDefaultFillPaint(Color.white);
  }
  ByteArrayOutputStream image = new ByteArrayOutputStream();
  ChartUtils.writeChartAsPNG(image, chart, width, height);
  return image.toByteArray();
}
 
Example 3
Source File: TICPlot.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void switchDataPointsVisible() {

    Boolean dataPointsVisible = null;
    final int count = plot.getDatasetCount();
    for (int i = 0; i < count; i++) {

      if (plot.getRenderer(i) instanceof XYLineAndShapeRenderer) {

        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(i);
        if (dataPointsVisible == null) {
          dataPointsVisible = !renderer.getDefaultShapesVisible();
        }
        renderer.setDefaultShapesVisible(dataPointsVisible);
      }
    }
  }
 
Example 4
Source File: LogVisualizer.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
private Map<String, JFreeChart> drawCharts(Map<String, Map<String, TimeSeries>> taggedTimeSeries,
    VisualizationPlan plan) {
  Map<String, JFreeChart> charts = new HashMap<>();
  for (Entry<String, Map<String, TimeSeries>> entry : taggedTimeSeries.entrySet()) {
    String measurementName = entry.getKey();
    TimeSeriesCollection timeSeriesList = new TimeSeriesCollection();
    for (TimeSeries timeSeries : entry.getValue().values()) {
      timeSeriesList.addSeries(timeSeries);
    }
    // add the start time of the timeseries to the x-axis name
    Date startDate = new Date((long) timeSeriesList.getDomainBounds(true).getLowerBound());
    JFreeChart chart = ChartFactory.createTimeSeriesChart(measurementName, "time-"+ startDate, measurementName,
        timeSeriesList);
    XYPlot xyPlot = chart.getXYPlot();
    XYLineAndShapeRenderer xyLineAndShapeRenderer = ((XYLineAndShapeRenderer) xyPlot
        .getRenderer());
    // show the origin data points in the plot
    xyLineAndShapeRenderer.setDefaultShapesVisible(true);
    xyLineAndShapeRenderer.setDefaultShapesFilled(true);
    if (plan.getMeasurementPositions() == null) {
      // do not draw lines if we only record the time instances of the logs (no measurements)
      xyLineAndShapeRenderer.setDefaultLinesVisible(false);
    }
    charts.put(measurementName, chart);
  }
  return charts;
}
 
Example 5
Source File: AlignmentRansacPlot.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public AlignmentRansacPlot() {
  super(ChartFactory.createXYLineChart("", null, null, new XYSeriesCollection(),
      PlotOrientation.VERTICAL, true, true, false));

  chart = this.getChart();
  chart.setBackgroundPaint(Color.white);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);

  // legend constructed by ChartFactory
  legend = chart.getLegend();
  legend.setItemFont(legendFont);
  legend.setFrame(BlockBorder.NONE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
  dataset = (XYSeriesCollection) plot.getDataset();

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties

  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  // set default renderer properties
  XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
  renderer.setDefaultLinesVisible(false);
  renderer.setDefaultShapesVisible(true);
  renderer.setSeriesShape(0, dataPointsShape);
  renderer.setSeriesShape(1, dataPointsShape);
  renderer.setSeriesLinesVisible(2, true);
  renderer.setSeriesShapesVisible(2, false);
  renderer.setSeriesPaint(0, Color.RED);
  renderer.setSeriesPaint(1, Color.GRAY);
  renderer.setSeriesPaint(2, Color.BLUE);
  renderer.setDefaultItemLabelPaint(labelsColor);
  renderer.setDrawSeriesLineAsPath(true);

  plot.setRenderer(renderer);

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 6
Source File: ReportPage.java    From freeacs with MIT License 4 votes vote down vote up
private void displayReportChartWithImageMap(
    Map<String, Object> root,
    int numberOfColumns,
    int averageLengthPrLegend,
    List<String> aggregation,
    HttpSession session) {
  StringWriter stringWriter = new StringWriter();
  PrintWriter writer = new PrintWriter(stringWriter);

  boolean shouldZoom = true;

  switch (reportType) {
    case JOB:
    case UNIT:
      shouldZoom = false;
      break;
    default:
      break;
  }

  String clickablePointUrl = "";
  if (shouldZoom || periodType.getSelected().isLongerThan(PeriodType.HOUR)) {
    clickablePointUrl =
        generateClickablePointUrl(
            periodType.getSelected(),
            reportType.getName(),
            method.getSelected(),
            optionalmethod.getSelected());
  }

  XYPlot plot = (XYPlot) chart.getPlot();
  XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
  XYURLGenerator urls = new ReportURLGenerator(clickablePointUrl, chart, aggregation);
  renderer.setURLGenerator(urls);
  XYSeriesLabelGenerator slg =
      new CustomXYSeriesLabelGenerator("javascript:xAPS.report.updateReport(%d);");
  renderer.setLegendItemURLGenerator(slg);
  renderer.setDefaultShapesVisible(true);
  renderer.setDrawOutlines(true);
  renderer.setUseFillPaint(true);
  renderer.setDefaultFillPaint(Color.white);

  try {
    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    ByteArrayOutputStream image = new ByteArrayOutputStream();

    int chartWidth = 700 + 10 * averageLengthPrLegend * numberOfColumns + 35 * numberOfColumns;

    ChartUtils.writeChartAsPNG(image, chart, chartWidth, 400, info);

    session.setAttribute("JFreeChartPNG" + reportType.getName(), image.toByteArray());

    ImageMapUtils.writeImageMap(
        writer,
        "chart" + reportType.getName(),
        info,
        arg0 -> " title=\"" + arg0 + "\" alt=\"" + arg0 + "\"",
        arg0 -> " href=\"" + arg0 + "\"");

    writer.println(
        "<img src=\""
            + Page.REPORT.getUrl()
            + "&type="
            + reportType.getName()
            + "&image=true&d="
            + new Date().getTime()
            + "\" border=\"0\" usemap=\"#chart"
            + reportType.getName()
            + "\" id=\"ImageMapImg\" alt=\"ReportImage\"/>");
    writer.close();

    root.put("imagemap", stringWriter.toString());
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
Example 7
Source File: Chart.java    From freeacs with MIT License 4 votes vote down vote up
/**
 * All params can be null.
 *
 * @param min - the minimum number on the left range axis (must be set if max is set)
 * @param max - the maximum number on the left range axis (must be set if min is set)
 * @param method2 - the method to run out of Record, and populates a bar series (right range axis)
 * @param highLightIndex - the index to highlight
 * @return
 * @throws Exception
 */
public JFreeChart makeTimeChart(Double min, Double max, String method2, Integer highLightIndex)
    throws Exception {
  startTms = System.currentTimeMillis();
  endTms = 0;
  XYBarRenderer.setDefaultShadowsVisible(false);
  TimeSeriesCollection data = new TimeSeriesCollection();
  Map<String, TimeSeries> timeSeriesMap = makeTimeSeriesMap(method, recordMap, keyNames);
  for (TimeSeries timeSeries : timeSeriesMap.values()) {
    data.addSeries(timeSeries);
  }
  String yAxisLabel = method;
  String denominator = Record.getDenominator(report.getRecordClass(), method.toLowerCase());
  if (denominator != null) {
    yAxisLabel += " (" + denominator + ")";
  }
  chart = ChartFactory.createTimeSeriesChart(title, "Time", yAxisLabel, data, true, true, true);
  XYPlot plot = (XYPlot) chart.getPlot();
  if (method2 != null) {
    Map<Key, R> recordMap2 = recordMap;
    TimeSeriesCollection data2 = new TimeSeriesCollection();
    if (keyNames.length > 0) {
      recordMap2 = report.getMapAggregatedOn();
    }
    Map<String, TimeSeries> timeSeriesMap2 = makeTimeSeriesMap(method2, recordMap2);
    if (timeSeriesMap2.get("Total (" + method2 + ")") != null) {
      data2.addSeries(timeSeriesMap2.get("Total (" + method2 + ")"));
    }
    String y2AxisLabel = method2;
    String demoninator2 = Record.getDenominator(report.getRecordClass(), method2.toLowerCase());
    if (demoninator2 != null) {
      y2AxisLabel += " (" + demoninator2 + ")";
    }
    NumberAxis axis2 = new NumberAxis(y2AxisLabel);
    XYBarRenderer renderer2 = new XYBarRenderer(0.20);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);
    plot.mapDatasetToRangeAxis(1, 1);
    renderer2.setBarPainter(new StandardXYBarPainter());
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
  }
  if (min != null && max != null) {
    plot.getRangeAxis(0).setRange(min, max);
  }

  if (highLightIndex != null) {
    chart.getXYPlot().getRenderer().setSeriesStroke(highLightIndex, new BasicStroke(5f));
  }

  XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
  renderer.setDefaultShapesVisible(true);
  renderer.setUseFillPaint(true);
  renderer.setDefaultFillPaint(Color.white);

  long diff = endTms - startTms;
  String format;
  if (diff > NINTY_DAYS) {
    format = "MMM-yyyy";
  } else if (diff > TWO_DAYS) {
    format = "dd-MMM";
  } else if (diff > TWO_MINUTES) {
    format = "HH:mm";
  } else {
    format = "HH:mm:ss";
  }
  DateAxis axis = (DateAxis) plot.getDomainAxis();
  axis.setDateFormatOverride(new SimpleDateFormat(format));

  LegendTitle lt = chart.getLegend(0);
  lt.setPosition(RectangleEdge.RIGHT);

  if (displayFrame) {
    ChartFrame frame = new ChartFrame(title, chart);
    frame.pack();
    frame.setVisible(true);
  }

  return chart;
}
 
Example 8
Source File: NumberLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
public NumberLineChart() {	
		this.collection = this.getCollection();
		initial();
		this.chart = ChartFactory.createXYLineChart(
				null, 
				"Request",
				"Hit Rate", 
				collection, 
				PlotOrientation.VERTICAL, 
				true, 
				true, 
				false
		);
		
		this.chart.getPlot().setBackgroundPaint(SystemColor.white);
		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		

		
		XYPlot plot = (XYPlot) chart.getPlot();		
		
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setTickUnit(new NumberTickUnit(500));
//		numberAxisX.setAutoRangeMinimumSize(0.1);
		numberAxisX.setAutoRangeIncludesZero(true);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);

		
		
		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(new NumberTickUnit(0.2));
		numberAxisY.setRangeWithMargins(0,1);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		// ����Y������Ϊ�ٷֱ�
		numberAxisY.setNumberFormatOverride(NumberFormat.getPercentInstance());
		
		
		
		XYItemRenderer xyitem = plot.getRenderer();   
        xyitem.setDefaultItemLabelsVisible(true);
//        ItemLabelsVisible(true);

		xyitem.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 12));
		xyitem.setDefaultItemLabelFont(new Font("Dialog", 1, 12));
        plot.setRenderer(xyitem);
		
		 	XYLineAndShapeRenderer renderer =  (XYLineAndShapeRenderer)plot.getRenderer();
			renderer.setDefaultItemLabelsVisible(true);
			renderer.setDefaultShapesVisible(true);
			renderer.setDrawOutlines(true);
			
			renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));


			
			renderer.setSeriesPaint(0, Color.RED);
			renderer.setSeriesPaint(1, new Color(53,101,253));
			renderer.setSeriesPaint(2, new Color(0,161,59));//����ɫ
			renderer.setSeriesPaint(3, new Color(148,103,189));//��ɫ
			

			renderer.setSeriesStroke(0, new BasicStroke(4.0F));
			renderer.setSeriesStroke(1, new BasicStroke(4.0F));
			renderer.setSeriesStroke(2, new BasicStroke(4.0F));
			renderer.setSeriesStroke(3, new BasicStroke(4.0F));
			renderer.setSeriesStroke(4, new BasicStroke(2.0F));
			renderer.setSeriesStroke(5, new BasicStroke(2.0F));
		
			this.chartFrame = new ChartFrame("Line Chart", chart);
			chartFrame.pack();
			chartFrame.setSize(1600,1200);
			chartFrame.setLocation(300,200);
			chartFrame.setVisible(true);
	}
 
Example 9
Source File: BaseLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
protected void generateLineChart(String xAisTitle, String yAisTitle,
									 NumberTickUnit xAisSpace, NumberTickUnit yAisSpace, double yaisMinValue, double yAisMaxValue,
									 XYSeriesCollection collection) {
		this.chart = ChartFactory.createXYLineChart(null, xAisTitle, yAisTitle,
				collection, PlotOrientation.VERTICAL, true, true, false);

		this.chart.getPlot().setBackgroundPaint(SystemColor.white);

		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		XYPlot plot = (XYPlot) chart.getPlot();
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setAutoRangeIncludesZero(false);

		numberAxisX.setTickUnit(xAisSpace);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);

		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(yAisSpace);
		numberAxisY.setRangeWithMargins(yaisMinValue, yAisMaxValue);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		numberAxisY.setNumberFormatOverride(NumberFormat.getNumberInstance());

		XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot
				.getRenderer();
//		renderer.setBaseItemLabelsVisible(true);
		renderer.setDefaultItemLabelsVisible(true);
		renderer.setDefaultShapesVisible(true);
//		renderer.setBaseShapesVisible(true);
		renderer.setDrawOutlines(true);

		renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(4, new BasicStroke(5F));

		renderer.setSeriesPaint(0, Color.RED);
		renderer.setSeriesPaint(1, Color.BLUE);
		renderer.setSeriesPaint(2, new Color(255, 125, 11));
		renderer.setSeriesPaint(3, new Color(0, 161, 59));
		renderer.setSeriesPaint(4, new Color(148, 103, 189));

		renderer.setSeriesStroke(0, new BasicStroke(4.0F));
		renderer.setSeriesStroke(1, new BasicStroke(4.0F));
		renderer.setSeriesStroke(2, new BasicStroke(4.0F));
		renderer.setSeriesStroke(3, new BasicStroke(4.0F));
		renderer.setSeriesStroke(4, new BasicStroke(2.0F));
		renderer.setSeriesStroke(5, new BasicStroke(2.0F));

		// renderer.setUseFillPaint(true);

		this.chartFrame = new ChartFrame("Line Chart", chart);
		chartFrame.pack();
		chartFrame.setSize(800, 600);
		chartFrame.setLocation(300, 200);
		chartFrame.setVisible(true);
	}
 
Example 10
Source File: TrafficLoadLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
public TrafficLoadLineChart() {	
		this.collection = this.getCollection();
		initial();
		this.chart = ChartFactory.createXYLineChart(
				null, 
				"Time Slice",
				"Traffic Load(100GB)", 
				collection, 
				PlotOrientation.VERTICAL, 
				true, 
				true, 
				false
		);
		this.chart.getPlot().setBackgroundPaint(SystemColor.white);
		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		

		
		XYPlot plot = (XYPlot) chart.getPlot();		
		
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setAutoRangeIncludesZero(false);
		
		numberAxisX.setAutoRangeMinimumSize(0.1);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);
		
		
		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(new NumberTickUnit(5));
		numberAxisY.setRangeWithMargins(0,40);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		numberAxisY.setNumberFormatOverride(NumberFormat.getNumberInstance());

		
		
		XYLineAndShapeRenderer renderer =  (XYLineAndShapeRenderer)plot.getRenderer();
		renderer.setDefaultItemLabelsVisible(true);
		renderer.setDefaultShapesVisible(true);
		renderer.setDrawOutlines(true);
			
		renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));
		renderer.setSeriesOutlineStroke(4, new BasicStroke(5F));



			
		renderer.setSeriesPaint(1, Color.RED);
		renderer.setSeriesPaint(2, new Color(53,101,253));
		renderer.setSeriesPaint(3, new Color(0,161,59));//����ɫ
		renderer.setSeriesPaint(4, new Color(148,103,189));//��ɫ
		renderer.setSeriesPaint(0, new Color(255,125,11));//�ٻ�ɫ

			

		renderer.setSeriesStroke(0, new BasicStroke(4.0F));
		renderer.setSeriesStroke(1, new BasicStroke(4.0F));
		renderer.setSeriesStroke(2, new BasicStroke(4.0F));
		renderer.setSeriesStroke(3, new BasicStroke(4.0F));
		renderer.setSeriesStroke(4, new BasicStroke(2.0F));
		renderer.setSeriesStroke(5, new BasicStroke(2.0F));




//		renderer.setUseFillPaint(true);
		
		
		this.chartFrame = new ChartFrame("Line Chart", chart);
		chartFrame.pack();
		chartFrame.setSize(1600,1200);
		chartFrame.setLocation(300,200);
		chartFrame.setVisible(true);
	}
 
Example 11
Source File: FXGraphics2DDemo1.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "International Coffee Organisation : Coffee Prices",    // title
        null,             // x-axis label
        "US cents/lb",      // y-axis label
        dataset);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setDefaultShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setDefaultStroke(new BasicStroke(3.0f, 
                BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), false);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
        renderer.setDefaultLegendTextFont(new Font(fontName, Font.PLAIN, 14));
    }

    return chart;

}
 
Example 12
Source File: TimeSeriesChartFXDemo1.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "International Coffee Organisation : Coffee Prices",    // title
        null,             // x-axis label
        "US cents/lb",      // y-axis label
        dataset);

    String fontName = "Palatino";
    chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
    chart.addSubtitle(new TextTitle("Source: http://www.ico.org/historical/2010-19/PDF/HIST-PRICES.pdf", 
            new Font(fontName, Font.PLAIN, 14)));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    chart.getLegend().setFrame(BlockBorder.NONE);
    chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setDefaultShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setDefaultStroke(new BasicStroke(3.0f));
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesPaint(1, new Color(24, 123, 58));
        renderer.setSeriesPaint(2, new Color(149, 201, 136));
        renderer.setSeriesPaint(3, new Color(1, 62, 29));
        renderer.setSeriesPaint(4, new Color(81, 176, 86));
        renderer.setSeriesPaint(5, new Color(0, 55, 122));
        renderer.setSeriesPaint(6, new Color(0, 92, 165));
    }

    return chart;

}
 
Example 13
Source File: AlignmentRansacPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public AlignmentRansacPlot() {
  super(null, true);

  dataset = new XYSeriesCollection();
  chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true,
      true, false);

  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);

  // legend constructed by ChartFactory
  legend = chart.getLegend();
  legend.setItemFont(legendFont);
  legend.setFrame(BlockBorder.NONE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties

  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  // set default renderer properties
  XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
  renderer.setDefaultLinesVisible(false);
  renderer.setDefaultShapesVisible(true);
  renderer.setSeriesShape(0, dataPointsShape);
  renderer.setSeriesShape(1, dataPointsShape);
  renderer.setSeriesLinesVisible(2, true);
  renderer.setSeriesShapesVisible(2, false);
  renderer.setSeriesPaint(0, Color.RED);
  renderer.setSeriesPaint(1, Color.GRAY);
  renderer.setSeriesPaint(2, Color.BLUE);
  renderer.setDefaultItemLabelPaint(labelsColor);
  renderer.setDrawSeriesLineAsPath(true);

  plot.setRenderer(renderer);


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}