Example usage for org.jfree.chart.plot XYPlot setDomainGridlinePaint

List of usage examples for org.jfree.chart.plot XYPlot setDomainGridlinePaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDomainGridlinePaint.

Prototype

public void setDomainGridlinePaint(Paint paint) 

Source Link

Document

Sets the paint for the grid lines plotted against the domain axis, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:edu.ucla.stat.SOCR.chart.SuperNormalDistributionChart.java

/**
 * Creates a chart./*from   ww w . j a v a2s.com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo1.java

/**
 * Creates the demo chart.//from  www  .jav  a 2  s  . c om
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart1 = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, //"Time of Day", 
            rangeLabel, //"Value",
            dataset, !legendPanelOn, true, false);

    chart1.setBackgroundPaint(Color.white);
    XYPlot plot = chart1.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairVisible(false);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(Color.black);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //         setXSummary(dataset); X is time
    return chart1;
}

From source file:com.view.TimeSeriesChartView.java

public JFreeChart getTimeSeriesChart(Excel theExcel, ReceivingControl theRC) {

    System.out.println(theRC.getNumberOfItem());
    System.out.println(theRC.getNumberOfSite());
    System.out.println(theRC.getNumberOfVendor());
    System.out.println(theRC.getVendorInfo());
    System.out.println(theRC.getSiteInfo());
    System.out.println(theRC.getItemInfo());

    //        TimeSeries item1_xy_data = new TimeSeries("Item1");
    //        TimeSeries item2_xy_data = new TimeSeries("Item2");
    //        TimeSeries item3_xy_data = new TimeSeries("Item3");
    ArrayList<Receiving> theReceiving = theExcel.getSheetReceiving();

    //        HashMap<Month, Integer> item1Map = new HashMap<>();
    //        HashMap<Month, Integer> item2Map = new HashMap<>();
    //        HashMap<Month, Integer> item3Map = new HashMap<>();

    TimeSeries data[] = new TimeSeries[theRC.getNumberOfItem()];
    HashMap<Month, Integer> itemMap[] = new HashMap[theRC.getNumberOfItem()];
    for (int i = 0; i < theRC.getNumberOfItem(); i++) {
        String itemName = "item" + i;
        data[i] = new TimeSeries(itemName);
        itemMap[i] = new HashMap<>();
    }//from w  w w .j  av a 2s .  c o m
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < theReceiving.size(); i++) {
        cal.setTime(theReceiving.get(i).getDate());
        int month = cal.get(Calendar.MONTH) + 1;
        int year = cal.get(Calendar.YEAR);
        int quantity = theReceiving.get(i).getQuantity();
        Month theMonth = new Month(month, year);
        int itemNum = theReceiving.get(i).getItem() - 1;
        itemMap[itemNum].put(theMonth, updateItemMap(itemMap[itemNum], theMonth, quantity));
        //            if (theReceiving[i].getItem() == 1)
        //            {
        //                item1Map.put(theMonth, updateItemMap(item1Map, theMonth, quantity));
        //            }
        //            else if (theReceiving[i].getItem() == 2)
        //            {
        //                item2Map.put(theMonth, updateItemMap(item2Map, theMonth, quantity));
        //            }
        //            else if (theReceiving[i].getItem() == 3)
        //            {
        //                item3Map.put(theMonth, updateItemMap(item3Map, theMonth, quantity));
        //            }
    }
    TimeSeriesCollection my_data_series = new TimeSeriesCollection();
    for (int i = 0; i < theRC.getNumberOfItem(); i++) {
        for (Map.Entry<Month, Integer> entry : itemMap[i].entrySet()) {
            data[i].add(entry.getKey(), entry.getValue());
        }
        my_data_series.addSeries(data[i]);
    }

    // add series using addSeries method
    //        my_data_series.addSeries(item1_xy_data);
    //        my_data_series.addSeries(item2_xy_data);
    //        my_data_series.addSeries(item3_xy_data);        
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Receiving", "Month", "Quantity", my_data_series,
            true, true, false);
    chart.setBackgroundPaint(Color.YELLOW);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.GREEN);
    plot.setRangeGridlinePaint(Color.orange);
    plot.setAxisOffset(new RectangleInsets(50, 0, 20, 5));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MM.yyyy"));
    return chart;
}

From source file:com.trivadis.loganalysis.ui.ChartPanel.java

private JFreeChart createChart(final XYDataset dataset, final Composite parent, final IChart data,
        final String chartName, final String xAxisLabel, final String yAxisLabel) {
    final JFreeChart chart = ChartFactory.createXYLineChart(chartName, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.lightGray);

    final ChartComposite chartComposite = new ChartComposite(parent, SWT.NONE, chart, true);
    chartComposite.setLayoutData(new GridDataBuilder().fill().build());
    return chart;
}

From source file:ec.ui.view.res.ResidualsView.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(themeSupport.getAreaColor(MAIN_COLOR));
    renderer.setBaseOutlinePaint(themeSupport.getLineColor(MAIN_COLOR));
}

From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer4xPhenomenons.java

public JFreeChart renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon) {
    // which observedProperty has been used?:
    ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty");
    if (observedPropertyPS.hasMultipleSpecifiedValues()) {
        observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class);
    } else if (observedPropertyPS.hasSingleSpecifiedValue()) {
        observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() };
    } else {// w  w w .ja  v a  2  s .  com
        throw new IllegalArgumentException("no observedProperties found.");
    }

    String[] foiIdArray;
    ParameterShell foiParamShell = paramCon.getParameterShellWithServiceSidedName("featureOfInterest");
    if (foiParamShell.hasMultipleSpecifiedValues()) {
        foiIdArray = foiParamShell.getSpecifiedTypedValueArray(String[].class);
    } else {
        foiIdArray = new String[] { (String) foiParamShell.getSpecifiedValue() };
    }

    ObservationSeriesCollection tuples4FOI = new ObservationSeriesCollection(observationCollection, foiIdArray,
            observedProperties, false);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            "Date", // x-axis label
            observedProperties[0], // y-axis label
            createDataset(foiIdArray, tuples4FOI, 0), // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // add additional datasets:

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat());

    for (int i = 1; i < observedProperties.length; i++) {
        XYDataset additionalDataset = createDataset(foiIdArray, tuples4FOI, i);
        plot.setDataset(i, additionalDataset);
        plot.setRangeAxis(i, new NumberAxis(observedProperties[i]));
        plot.getRangeAxis(i).setRange((Double) tuples4FOI.getMinimum(i), (Double) tuples4FOI.getMaximum(i));
        plot.mapDatasetToRangeAxis(i, i);
    }

    return chart;
}

From source file:br.prof.salesfilho.oci.image.GraphicBuilder.java

public void createChart() {
    chart = ChartFactory.createXYLineChart(this.title, this.xLabel, this.yLabel, this.collectionDataset,
            PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    List<XYSeries> listSeries = collectionDataset.getSeries();
    for (int i = 0; i < listSeries.size(); i++) {
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShapesFilled(i, false);
    }/* w  ww . java 2 s  .  c om*/

    plot.setRenderer(renderer);
    plot.setRangePannable(true);
    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel.setChart(chart);

}

From source file:net.pickapack.chart.LinePlotFrame.java

/**
 * Create a line plot frame./*from  w w w  .  java2 s.  co m*/
 *
 * @param linePlot the line plot
 * @param width the width
 * @param height the height
 */
public LinePlotFrame(LinePlot linePlot, int width, int height) {
    super(linePlot.getTitle());
    this.linePlot = linePlot;

    this.numSubPlots = linePlot.getSubLinePlots().size();

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.dataSets = new ArrayList<TimeSeriesCollection>();
    this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>();

    for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) {
        TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection();
        this.dataSets.add(dataSetsPerSubPlot);

        HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>();
        this.dataSinks.add(dataSinksPerSubPlot);

        for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) {
            TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle());
            dataSetsPerSubPlot.addSeries(timeSeries);
            dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback());
        }

        NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY());
        rangeAxis.setAutoRangeIncludesZero(false);
        XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer());
        subplot.setBackgroundPaint(Color.lightGray);
        subplot.setDomainGridlinePaint(Color.white);
        subplot.setRangeGridlinePaint(Color.white);
        plot.add(subplot);
    }

    JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(3600000.0);

    JPanel content = new JPanel(new BorderLayout());

    ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

    DataSink dataSink = new DataSink();
    new Thread(dataSink).start();
}

From source file:LineChartDemo6.java

/**
 * Creates a chart./*w w w .  ja  v  a 2s . c o m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //renderer.setSeriesLinesVisible(0, false);
    //renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.jfree.chart.demo.CrosshairDemo1.java

/**
 * Creates a chart./*from  w  w w .  ja v a 2  s . c  o m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYLineChart("Crosshair Demo 1", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(true);

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setShapesFilled(true);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}