Java Code Examples for org.jfree.chart.plot.XYPlot#setDomainGridlinesVisible()

The following examples show how to use org.jfree.chart.plot.XYPlot#setDomainGridlinesVisible() . 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: BeltNumericalColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			PlotOrientation.VERTICAL, false, false, false);
	AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainZeroBaselineVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 2
Source File: ChartManager.java    From jamel with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns a new plot with the specified dataset, axes and
 * renderer.
 * 
 * @param dataset
 *            the dataset (<code>null</code> permitted).
 * @param xAxis
 *            the x axis (<code>null</code> permitted).
 * @param yAxis
 *            the y axis (<code>null</code> permitted).
 * @param renderer
 *            the renderer (<code>null</code> permitted).
 * @return a new plot.
 */
private static XYPlot createXYPlot(XYDataset dataset, NumberAxis xAxis, NumberAxis yAxis, XYItemRenderer renderer) {
	final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
	plot.setOrientation(PlotOrientation.VERTICAL);
	plot.setDomainGridlinesVisible(false);
	plot.setDomainMinorGridlinesVisible(false);
	plot.setRangeGridlinesVisible(false);
	plot.setRangeMinorGridlinesVisible(false);
	plot.setRangeCrosshairVisible(false);
	plot.setDomainCrosshairVisible(false);
	plot.setBackgroundPaint(Color.white);
	// plot.getRangeAxis().setLabelFont(axisLabelFont);
	// plot.getDomainAxis().setLabelFont(axisLabelFont);
	plot.setDomainZeroBaselineVisible(true);
	plot.setRangeZeroBaselineVisible(true);
	return plot;
}
 
Example 3
Source File: NumericalAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 *
 * @param exampleSet
 * @return
 */
private JFreeChart createHistogramChart(ExampleSet exampleSet) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet),
			PlotOrientation.VERTICAL, false, false, false);
	AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainZeroBaselineVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 4
Source File: DateTimeAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 *
 * @param exampleSet
 * @return
 */
private JFreeChart createHistogramChart(final ExampleSet exampleSet) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet),
			PlotOrientation.VERTICAL, false, false, false);
	AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainZeroBaselineVisible(false);
	plot.getDomainAxis().setTickLabelsVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 5
Source File: BeltTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(final Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			PlotOrientation.VERTICAL, false, false, false);
	setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainZeroBaselineVisible(false);
	plot.getDomainAxis().setTickLabelsVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 6
Source File: BeltDateTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 */
private JFreeChart createHistogramChart(final Table table) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(table),
			PlotOrientation.VERTICAL, false, false, false);
	setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainZeroBaselineVisible(false);
	plot.getDomainAxis().setTickLabelsVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example 7
Source File: AegeanChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createScatterChart() throws JRException
{
	JFreeChart jfreeChart = super.createScatterChart();
	XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
	xyPlot.setDomainGridlinesVisible(false);
	XYLineAndShapeRenderer plotRenderer = (XYLineAndShapeRenderer) ((XYPlot)jfreeChart.getPlot()).getRenderer();
	plotRenderer.setBaseShapesFilled(false);
	plotRenderer.setBaseStroke(new BasicStroke(1f));
	return jfreeChart;
}
 
Example 8
Source File: VariablePlot.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public VariablePlot(PreferencesExt prefs) {
  // this.prefs = prefs;

  setLayout(new BorderLayout());
  TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

  chart = createChart();

  ChartPanel chartPanel = new ChartPanel(chart);
  chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
  chartPanel.setMouseZoomable(true, false);

  if (prefs != null)
    chartPanel.setBounds((Rectangle) prefs.getBean("PlotWindowBounds", new Rectangle(300, 300, 600, 600)));
  else
    chartPanel.setBounds(new Rectangle(300, 300, 600, 600));

  XYPlot plot = chart.getXYPlot();

  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinePaint(Color.GRAY);
  plot.setDomainGridlinesVisible(true);
  plot.setRangeGridlinePaint(Color.GRAY);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
  LegendTitle legend = chart.getLegend();
  if (legend != null) {
    legend.setPosition(RectangleEdge.BOTTOM);
  }
  add(chartPanel);

}
 
Example 9
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createScatterChart() throws JRException
{
	JFreeChart jfreeChart = super.createScatterChart();
	XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
	
	xyPlot.setRangeGridlinePaint(SCATTER_GRIDLINE_COLOR);
	xyPlot.setRangeGridlineStroke(new BasicStroke(0.75f));
	xyPlot.setDomainGridlinesVisible(true);
	xyPlot.setDomainGridlinePaint(SCATTER_GRIDLINE_COLOR);
	xyPlot.setDomainGridlineStroke(new BasicStroke(0.75f));
	xyPlot.setRangeZeroBaselinePaint(ChartThemesConstants.GRAY_PAINT_134);

	XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer)xyPlot.getRenderer();
	lineRenderer.setUseFillPaint(true);
	JRScatterPlot scatterPlot = (JRScatterPlot) getPlot();
	boolean isShowLines = scatterPlot.getShowLines() == null ? false : scatterPlot.getShowLines();
	lineRenderer.setBaseLinesVisible(isShowLines);
	XYDataset xyDataset = xyPlot.getDataset();
	if (xyDataset != null)
	{
		for (int i = 0; i < xyDataset.getSeriesCount(); i++)
		{
			lineRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			lineRenderer.setSeriesFillPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
			lineRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(i));
			//lineRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6));
		}
	}
	return jfreeChart;
}
 
Example 10
Source File: GsnChartJfreechart.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public JFreeChart createChart(Collection<Data> datas) {
    TimeSeries t1 = new TimeSeries("S1");
    Iterator<Data> iter = datas.iterator() ; 
    Data data ;
    while (iter.hasNext()) {
        data = iter.next();
        t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long)data.getP2()), TimeZone.getDefault()), data.getValue());
    }
    XYDataset dataset = new TimeSeriesCollection(t1);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
            null,
            null, 
            null, 
            dataset, 
            false,
            false, 
            false
    );
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    chart.setBackgroundPaint(Color.WHITE);
    //
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("No Data to Display");
    plot.setDomainGridlinesVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInsets(new RectangleInsets(5,14,0,5));
    //
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(ssdf);
    axis.setTickLabelFont(TICK_FONT);
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickLabelFont(TICK_FONT);
    //
    return chart;
}
 
Example 11
Source File: AegeanChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void configurePlot(Plot plot, JRChartPlot jrPlot)
{

	super.configurePlot(plot, jrPlot);

	if(plot instanceof CategoryPlot)
	{
		CategoryPlot categoryPlot = (CategoryPlot)plot;
		CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
		CategoryDataset categoryDataset = categoryPlot.getDataset();
		if(categoryDataset != null)
		{
			for(int i = 0; i < categoryDataset.getRowCount(); i++)
			{
				categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			}
		}
		categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
		categoryPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
		categoryPlot.setDomainGridlinesVisible(false);
		categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
	}
	else if(plot instanceof XYPlot)
	{
		XYPlot xyPlot = (XYPlot)plot;
		XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
		XYDataset xyDataset = xyPlot.getDataset();
		if(xyDataset != null)
		{
			for(int i = 0; i < xyDataset.getSeriesCount(); i++)
			{
				xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			}
		}
		xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
		xyPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
		xyPlot.setDomainGridlinesVisible(false);
		xyPlot.setRangeZeroBaselineVisible(true);
	}
}
 
Example 12
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void configurePlot(Plot plot, JRChartPlot jrPlot)
{
	super.configurePlot(plot, jrPlot);
	if (plot instanceof CategoryPlot)
	{
		CategoryPlot categoryPlot = (CategoryPlot)plot;
		CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
		CategoryDataset categoryDataset = categoryPlot.getDataset();
		if (categoryDataset != null)
		{
			for (int i = 0; i < categoryDataset.getRowCount(); i++)
			{
				categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			}
		}
		categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);
		categoryPlot.setRangeGridlineStroke(new BasicStroke(1f));
		categoryPlot.setDomainGridlinesVisible(false);
		
	}
	else if (plot instanceof XYPlot)
	{
		XYPlot xyPlot = (XYPlot)plot;
		XYDataset xyDataset = xyPlot.getDataset();
		if (xyDataset != null)
		{
			XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
			for (int i = 0; i < xyDataset.getSeriesCount(); i++)
			{
				xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			}
		}
		xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);
		xyPlot.setRangeGridlineStroke(new BasicStroke(1f));
		xyPlot.setDomainGridlinesVisible(false);
		
		xyPlot.setRangeZeroBaselineVisible(true);

	}
}
 
Example 13
Source File: PlotUtil.java    From dl4j-tutorials with MIT License 4 votes vote down vote up
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0],maxs[0]);


    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0]-mins[0])/(nPoints-1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);


    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(),
            scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.red));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}
 
Example 14
Source File: SimpleScatterPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public SimpleScatterPlot(double[] xValues, double[] yValues, double[] colors, String xLabel,
    String yLabel) {
  super(null, true);

  setBackground(Color.white);
  setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

  xAxis = new NumberAxis(xLabel);
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setUpperMargin(0);
  xAxis.setLowerMargin(0);

  yAxis = new NumberAxis(yLabel);
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setUpperMargin(0);
  yAxis.setLowerMargin(0);

  xyDataset = new DefaultXYZDataset();
  int length = Math.min(xValues.length, yValues.length);
  double[][] data = new double[3][length];
  System.arraycopy(xValues, 0, data[0], 0, length);
  System.arraycopy(yValues, 0, data[1], 0, length);
  System.arraycopy(colors, 0, data[2], 0, length);
  xyDataset.addSeries(SERIES_ID, data);

  XYDotRenderer renderer = new XYDotRenderer() {
    @Override
    public Paint getItemPaint(int row, int col) {
      double c = xyDataset.getZ(row, col).doubleValue();
      return Color.getHSBColor((float) c, 1.0f, 1.0f);
    }
  };

  renderer.setDotHeight(3);
  renderer.setDotWidth(3);

  plot = new XYPlot(xyDataset, xAxis, yAxis, renderer);
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(true);
  plot.setRangeGridlinesVisible(true);

  chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false);
  chart.setBackgroundPaint(Color.white);

  super.setChart(chart);

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 15
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initChart(final IScope scope, final String chartname) {
	super.initChart(scope, chartname);

	final XYPlot pp = (XYPlot) chart.getPlot();
	pp.setDomainGridlinePaint(axesColor);
	pp.setRangeGridlinePaint(axesColor);
	pp.setDomainCrosshairPaint(axesColor);
	pp.setRangeCrosshairPaint(axesColor);
	pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
	pp.setDomainCrosshairVisible(false);
	pp.setRangeCrosshairVisible(false);
	pp.setRangeGridlinesVisible(false);
	pp.setDomainGridlinesVisible(false);

	pp.getDomainAxis().setAxisLinePaint(axesColor);

	pp.getDomainAxis().setTickLabelFont(getTickFont());
	pp.getDomainAxis().setLabelFont(getLabelFont());
	if (textColor != null) {
		pp.getDomainAxis().setLabelPaint(textColor);
		pp.getDomainAxis().setTickLabelPaint(textColor);
	}
	if (xtickunit > 0) {
		((NumberAxis) pp.getDomainAxis()).setTickUnit(new NumberTickUnit(xtickunit));
	}

	pp.getRangeAxis().setAxisLinePaint(axesColor);
	pp.getRangeAxis().setLabelFont(getLabelFont());
	pp.getRangeAxis().setTickLabelFont(getTickFont());
	if (textColor != null) {
		pp.getRangeAxis().setLabelPaint(textColor);
		pp.getRangeAxis().setTickLabelPaint(textColor);
	}
	if (ytickunit > 0) {
		((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(ytickunit));
	}

	// resetAutorange(scope);

	if (xlabel != null && !xlabel.isEmpty()) {
		pp.getDomainAxis().setLabel(xlabel);
	}
	if (ylabel != null && !ylabel.isEmpty()) {
		pp.getRangeAxis().setLabel(ylabel);
	}

}
 
Example 16
Source File: AnomalyGraphGenerator.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a chart containing the current/baseline data (in that order) as well as markers for
 * each anomaly interval. timeGranularity and windowMillis are used to determine the date format
 * and spacing for tick marks on the domain (x) axis.
 */
public JFreeChart createChart(final XYDataset dataset, final String metric,
    final TimeGranularity timeGranularity, final long windowMillis,
    final Map<MergedAnomalyResultDTO, String> anomaliesWithLabels) {

  // create the chart...
  final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // no chart title for email
                                                                    // image
      "Date (" + DEFAULT_TIME_ZONE.getID() + ")", // x axis label
      metric, // y axis label
      dataset, // data
      true, // include legend
      false, // tooltips - n/a if the chart will be saved as an img
      false // urls - n/a if the chart will be saved as an img
  );

  // get a reference to the plot for further customisation...
  final XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);

  // dashboard webapp currently uses solid blue for current and dashed blue for baseline
  // (5/2/2016)
  final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
  renderer.setSeriesShapesVisible(0, false);
  renderer.setSeriesShapesVisible(1, false);
  renderer.setSeriesPaint(0, Color.BLUE);
  renderer.setSeriesPaint(1, Color.BLUE);
  // http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm
  // set baseline to be dashed
  renderer.setSeriesStroke(1,
      new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {
          2.0f, 6.0f
      }, 0.0f));
  plot.setRenderer(renderer);

  DateAxis axis = (DateAxis) plot.getDomainAxis();
  DateTickUnit dateTickUnit = getDateTickUnit(timeGranularity, windowMillis);
  SimpleDateFormat dateFormat = getDateFormat(timeGranularity);
  axis.setDateFormatOverride(dateFormat);
  axis.setTickUnit(dateTickUnit);
  axis.setVerticalTickLabels(true);

  List<Marker> anomalyIntervals = getAnomalyIntervals(anomaliesWithLabels);
  for (Marker marker : anomalyIntervals) {
    plot.addDomainMarker(marker);
  }

  return chart;

}
 
Example 17
Source File: SimpleScatterPlot.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public SimpleScatterPlot(double[] xValues, double[] yValues, double[] colors, String xLabel,
    String yLabel) {
  super(null);

  // setBackground(Color.white);
  setCursor(Cursor.CROSSHAIR);

  xAxis = new NumberAxis(xLabel);
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setUpperMargin(0);
  xAxis.setLowerMargin(0);

  yAxis = new NumberAxis(yLabel);
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setUpperMargin(0);
  yAxis.setLowerMargin(0);

  xyDataset = new DefaultXYZDataset();
  int length = Math.min(xValues.length, yValues.length);
  double[][] data = new double[3][length];
  System.arraycopy(xValues, 0, data[0], 0, length);
  System.arraycopy(yValues, 0, data[1], 0, length);
  System.arraycopy(colors, 0, data[2], 0, length);
  xyDataset.addSeries(SERIES_ID, data);

  XYDotRenderer renderer = new XYDotRenderer() {
    @Override
    public Paint getItemPaint(int row, int col) {
      double c = xyDataset.getZ(row, col).doubleValue();
      return Color.getHSBColor((float) c, 1.0f, 1.0f);
    }
  };

  renderer.setDotHeight(3);
  renderer.setDotWidth(3);

  plot = new XYPlot(xyDataset, xAxis, yAxis, renderer);
  plot.setBackgroundPaint(Color.white);
  plot.setDomainGridlinesVisible(true);
  plot.setRangeGridlinesVisible(true);

  chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false);
  chart.setBackgroundPaint(Color.white);

  super.setChart(chart);

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