Java Code Examples for org.jfree.chart.ChartFactory#createTimeSeriesChart()

The following examples show how to use org.jfree.chart.ChartFactory#createTimeSeriesChart() . 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: HouseholdsPanel.java    From computational-economy with GNU General Public License v3.0 6 votes vote down vote up
protected ChartPanel createUtilityFunctionMechanicsPanel(final Currency currency) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).householdsModel.budgetModel.getTimeSeries());
	for (final ConvexFunctionTerminationCause terminationCause : ConvexFunctionTerminationCause.values()) {
		timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
				.getNationalEconomyModel(currency).householdsModel.convexFunctionTerminationCauseModels
						.get(terminationCause).getTimeSeries());
	}

	// budget is correct here
	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Utility Function Mechanics", "Date",
			"Budget Spent", timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 2
Source File: IndustriesPanel.java    From computational-economy with GNU General Public License v3.0 6 votes vote down vote up
protected ChartPanel createGoodTypeSupplyPanel(final Currency currency, final GoodType outputGoodType) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).getPricingBehaviourModel(outputGoodType).offerModel.getTimeSeries());
	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).getPricingBehaviourModel(outputGoodType).soldModel.getTimeSeries());
	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).getIndustryModel(outputGoodType).inventoryModel.getTimeSeries());
	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).getIndustryModel(outputGoodType).outputModel.getTimeSeries());

	final JFreeChart chart = ChartFactory.createTimeSeriesChart(outputGoodType.toString() + " Supply", "Date",
			"Supply", timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 3
Source File: TradeMonitorGui.java    From hazelcast-jet-training with Apache License 2.0 6 votes vote down vote up
private XYPlot createChartFrame(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "Average Stock Price over 1 minute", "Time", "Price in USD", dataset,
            true, true, false
    );
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(245, 245, 245));
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);

    final JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setTitle("Trade Monitor");
    frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLayout(new BorderLayout());
    frame.add(new ChartPanel(chart));
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent windowEvent) {
            avgPrices.removeEntryListener(listenerId);
        }
    });
    frame.setVisible(true);
    return plot;
}
 
Example 4
Source File: TimeSeriesChartDemo1.java    From buffer_bci with GNU General Public License v3.0 5 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(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
 
Example 5
Source File: TimeSeriesGraphTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void initUI() {
    final boolean displayLegend = true;
    final boolean showTooltips = true;
    final boolean showUrls = false;
    chart = ChartFactory.createTimeSeriesChart(null,
                                               DEFAULT_DOMAIN_LABEL,
                                               DEFAULT_RANGE_LABEL,
                                               null, displayLegend, showTooltips, showUrls);
    graphModel = new TimeSeriesGraphModel(chart.getXYPlot(), validator);
    graphForm = new TimeSeriesGraphForm(graphModel, chart, validator, HELP_ID);
    setDisplayName(Bundle.CTL_TimeSeriesGraphTopComponentName());
    setLayout(new BorderLayout());
    add(graphForm.getControl(), BorderLayout.CENTER);

    ProductSceneView selectedView = SnapApp.getDefault().getSelectedProductSceneView();
    if (selectedView != null) {
        maySetCurrentView(selectedView);
    }
    SnapApp.getDefault().getSelectionSupport(ProductSceneView.class).addHandler((oldValue, newValue) -> {
        if (oldValue != null) {
            maySetCurrentView(null);
        }
        if (newValue != null) {
            maySetCurrentView(newValue);
        }
    });
}
 
Example 6
Source File: TimeSeriesChartDemo1.java    From ccu-historian with GNU General Public License v3.0 5 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(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
 
Example 7
Source File: ChartVirtualSensor.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public void initialize ( ) {
   if ( !ready ) {
      chart = ChartFactory.createTimeSeriesChart( plotTitle , "Time" , verticalAxisTitle , dataCollectionForTheChart , true , true , false );
      chart.setBorderVisible( true );
      ready = true;
      logger.debug( "The Chart Virtual Sensor is ready." );
   }
}
 
Example 8
Source File: MoneyPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected ChartPanel createMoneyVelocityPanel() {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	for (final Currency currency : Currency.values()) {
		timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
				.getNationalEconomyModel(currency).moneyVelocityModel.getTimeSeries());
	}

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Velocity of Money", "Date", "Velocity of Money",
			timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 9
Source File: SWTTimeSeriesDemo.java    From SIMVA-SoS with Apache License 2.0 5 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(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);
    
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 10
Source File: SealedHistoryPricesPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
@Override
public JFreeChart initChart() {

	TimeSeriesCollection dataset = new TimeSeriesCollection();

	TimeSeries series1 = new TimeSeries(title);
		if(cpVariations!=null)
			for (Entry<Date, Double> d : cpVariations.entrySet())
				series1.add(new Day(d.getKey()), d.getValue().doubleValue());

		dataset.addSeries(series1);
	
	return ChartFactory.createTimeSeriesChart("Price Variation", "Date", "Value", dataset, true, true,false);
}
 
Example 11
Source File: HouseholdsPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected ChartPanel createWageDividendPanel(final Currency currency) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).householdsModel.wageModel.getTimeSeries());
	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).householdsModel.dividendModel.getTimeSeries());
	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).householdsModel.governmentTransfersModel.getTimeSeries());

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Wage, Dividend & Transfers", "Date",
			"Wage, Dividend & Transfers", timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 12
Source File: TimeSeriesChartDemo1.java    From openstock with GNU General Public License v3.0 5 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(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
 
Example 13
Source File: HouseholdsPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected ChartPanel createConsumptionSavingRatePanel(final Currency currency) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).householdsModel.consumptionRateModel.getTimeSeries());
	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).householdsModel.savingRateModel.getTimeSeries());

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Consumption & Saving Rate", "Date",
			"Consumption & Saving Rate", timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 14
Source File: FpsInfo.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
private JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "", "", xydataset, true,
        true, false);
    Plot plot = (Plot) jfreechart.getPlot();
    xyplot = jfreechart.getXYPlot();
    // 纵坐标设定
    valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    valueaxis.setFixedAutoRange(60000D);
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 20D);
    plot.setBackgroundPaint(Color.black);
    return jfreechart;
}
 
Example 15
Source File: MoneyPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected ChartPanel createMoneyCirculationPanel() {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	for (final Currency currency : Currency.values()) {
		timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
				.getNationalEconomyModel(currency).moneyCirculationModel.getTimeSeries());
	}

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Money Circulation", "Date", "Money Circulation",
			timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 16
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 17
Source File: TimeSeriesChartFXDemo1.java    From openstock with GNU General Public License v3.0 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.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setBaseStroke(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));
    }

    return chart;

}
 
Example 18
Source File: SWTMultipleAxisDemo1.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    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));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 19
Source File: GraphView.java    From High-Frequency-Data-Order-Book-Analyser with GNU General Public License v2.0 4 votes vote down vote up
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(
            graphTitle,
            "Time",
            "Price",
            dataset,
            true,
            true,
            false
    );

    plot = result.getXYPlot();

    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.lightGray);

    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);
    xaxis.setVisible(false);

    xaxis.setFixedAutoRange(16000.0);  // 60 seconds
    xaxis.setVerticalTickLabels(true);

    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setRange(0, 100.0);

    xaxis2 = new NumberAxis("Volume");

    plot.setDataset(1, dataset2);

    plot.setRangeAxis(1, xaxis2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYBarRenderer renderer2 = new XYBarRenderer(0.20);
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(
                    StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00")
            )
    );
    renderer2.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

    plot.setRenderer(1, renderer2);

    plot.setDataset(2, dataset3);

    plot.mapDatasetToRangeAxis(2, 0);

    XYErrorRenderer renderer3 = new XYErrorRenderer();
    plot.setRenderer(2, renderer3);

    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 1);
    XYBarRenderer renderer4 = new XYBarRenderer(0.20);

    plot.setRenderer(3, renderer4);

    return result;
}
 
Example 20
Source File: TimeSeriesChartFXDemo1.java    From ECG-Viewer with GNU General Public License v2.0 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.setBaseShapesVisible(false);
        renderer.setDrawSeriesLineAsPath(true);
        // set the default stroke for all series
        renderer.setAutoPopulateSeriesStroke(false);
        renderer.setBaseStroke(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));
    }

    return chart;

}