private JFreeChart buildDifferenceChart(TimeSeriesCollection dataset, String title) { // Creat the chart JFreeChart chart = ChartFactory.createTimeSeriesChart( title, "Date", "Price", dataset, true, // legend true, // tool tips false // URLs ); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setRenderer( new XYDifferenceRenderer(new Color(112, 128, 222), new Color(112, 128, 222), false)); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); ValueAxis domainAxis = new DateAxis("Date"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); plot.setForegroundAlpha(0.5f); return chart; }
public Chart(String title, String timeAxis, String valueAxis, TimeSeries data) { try { // Build the datasets dataset.addSeries(data); // Create the chart JFreeChart chart = ChartFactory.createTimeSeriesChart( title, timeAxis, valueAxis, dataset, true, true, false); // Setup the appearance of the chart chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // Tell the chart how we would like dates to read DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("EEE HH")); this.add(new ChartPanel(chart)); } catch (Exception e) { e.printStackTrace(); } }
private JFreeChart buildChart(TimeSeriesCollection dataset, String title, boolean endPoints) { // Create the chart JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Date", "Price", dataset, true, true, false); // Display each series in the chart with its point shape in the legend LegendTitle sl = chart.getLegend(); // sl.setDisplaySeriesShapes(true); // Setup the appearance of the chart chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // Display data points or just the lines? if (endPoints) { XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; // rr.setPlotShapes(true); rr.setShapesFilled(true); rr.setItemLabelsVisible(true); } } // Tell the chart how we would like dates to read DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
private JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart( "Dynamic Data Demo", "Time", "Value", xydataset, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(60000D); valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(0.0D, 200D); return jfreechart; }
/** * temporal helper function * * @param dataset * @return */ private JFreeChart createChart(TimeSeriesCollection dataset) { NumberAxis axis = new NumberAxis(null); axis.setAutoRangeIncludesZero(false); // parent=new CombinedRangeXYPlot(axis); // chart = null; // XYPlot plot2=new XYPlot(dataset2, new DateAxis(null), null, new StandardXYItemRenderer()); // XYPlot subplot2=new XYPldt(dataset2, new DateAxis("Date 2"), null, ) // parent.add(subplot1); // parent.add(subplot2); // chart=new JFreeChart(null, null, parent, false); chart = ChartFactory.createTimeSeriesChart(null, "", "", dataset, false, false, false); XYPlot plot1 = chart.getXYPlot(); plot1.setDataset(dataset); plot1.setRenderer(new StandardXYItemRenderer()); plot1.setSecondaryDataset(0, hld); CandlestickRenderer c1 = new CandlestickRenderer(); // c1.setAutoWidthFactor(1.0); // c1.setAutoWidthGap(0.1); c1.setBasePaint(new Color(255, 255, 255)); c1.setBaseOutlinePaint(new Color(255, 255, 255)); c1.setPaint(new Color(255, 255, 255)); c1.setUpPaint(new Color(255, 0, 0, 80)); c1.setDownPaint(new Color(0, 255, 0, 80)); plot1.setSecondaryRenderer(0, c1); // plot1.setSecondaryDataset(0, dataset2); XYDotRenderer xd1 = new XYDotRenderer(); // plot1.setSecondaryRenderer(0, new AreaXYRenderer(AreaXYRenderer.AREA_AND_SHAPES)); // plot1.setSecondaryRenderer(0, xd1); // chart=new JFreeChart("", null, plot1, false); chart.setBackgroundPaint(new Color(0, 0, 0)); return chart; }
public MyDemoPanel() { super(new BorderLayout()); lastValue = new double[3]; CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time")); datasets = new TimeSeriesCollection[3]; for (int i = 0; i < 3; i++) { lastValue[i] = 100D; TimeSeries timeseries = new TimeSeries("Random " + i); datasets[i] = new TimeSeriesCollection(timeseries); NumberAxis numberaxis = new NumberAxis("Y" + i); numberaxis.setAutoRangeIncludesZero(false); XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer()); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.add(xyplot); } JFreeChart jfreechart = new JFreeChart("Dynamic Data Demo 3", combineddomainxyplot); addChart(jfreechart); LegendTitle legendtitle = (LegendTitle) jfreechart.getSubtitle(0); legendtitle.setPosition(RectangleEdge.RIGHT); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart.setBorderPaint(Color.black); jfreechart.setBorderVisible(true); ValueAxis valueaxis = combineddomainxyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(20000D); ChartUtilities.applyCurrentTheme(jfreechart); ChartPanel chartpanel = new ChartPanel(jfreechart); add(chartpanel); JPanel jpanel = new JPanel(new FlowLayout()); for (int j = 0; j < 3; j++) { JButton jbutton1 = new JButton("Series " + j); jbutton1.setActionCommand("ADD_DATA_" + j); jbutton1.addActionListener(this); jpanel.add(jbutton1); } JButton jbutton = new JButton("ALL"); jbutton.setActionCommand("ADD_ALL"); jbutton.addActionListener(this); jpanel.add(jbutton); add(jpanel, "South"); chartpanel.setPreferredSize(new Dimension(500, 470)); chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
/** * Create a GUI that shows a graph for the specified user's payoff history * * @param user The user to show the Payoff history for */ public GraphGUI(User user) { super( user.getUserName() + "'s Payoff History (Over " + user.getPayoffHistory().size() + " Steps)"); this.userInfo = user; this.pack(); // Set size this.setMinimumSize(new Dimension(500, 500)); // Center the graph this.setLocationRelativeTo(null); // Create a series collection xySeriesCollection = new XYSeriesCollection(); // Create (refresh) chart data refreshChartData(); // Create an XY Line Chart chart = ChartFactory.createXYLineChart( "User Payoff Over Time", "Steps (Simulation Iterations)", "User Payoff", xySeriesCollection); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getPlot().setOutlinePaint(Color.BLACK); // Draw the Initial Chart chart.draw( (Graphics2D) this.getGraphics(), (Rectangle2D) new Rectangle2D.Double(0, 0, this.getWidth(), this.getHeight())); // Set the content pane to a graphics panel for drawing the graph this.setContentPane(new GraphPanel(this)); // Show the frame this.setVisible(true); // Subscribe to the user's UserPayoff events user.addPayoffListener(this); }
/** * Draws the chart using graphics * * @param g Graphics to Draw to */ public void drawChart(Graphics g) { // Update all chart data refreshChartData(); // Paint the chart if (chart != null && g != null) chart.draw( (Graphics2D) g, (Rectangle2D) new Rectangle2D.Double( 0, 0, g.getClipBounds().getWidth(), g.getClipBounds().getHeight())); }
/** Creates fundamental diagram chart. */ private JFreeChart makeFDChart() { updateFDSeries(); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(ffFD); dataset.addSeries(cFD); dataset.addSeries(cdFD); JFreeChart chart = ChartFactory.createXYLineChart( null, // chart title "Density (vpm)", // x axis label "Flow (vph)", // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend false, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); plot.getRenderer().setSeriesPaint(0, Color.GREEN); plot.getRenderer().setSeriesPaint(1, Color.RED); plot.getRenderer().setSeriesPaint(2, Color.BLUE); plot.getRenderer().setStroke(new BasicStroke(2)); return chart; }
protected void buildChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); chart = ChartFactory.createMultiplePieChart( "Untitled Chart", dataset, org.jfree.util.TableOrder.BY_COLUMN, false, true, false); chart.setAntiAlias(true); // chartPanel = new ScrollableChartPanel(chart, true); chartPanel = buildChartPanel(chart); // chartHolder.getViewport().setView(chartPanel); setChartPanel(chartPanel); JFreeChart baseChart = (JFreeChart) ((MultiplePiePlot) (chart.getPlot())).getPieChart(); PiePlot base = (PiePlot) (baseChart.getPlot()); base.setIgnoreZeroValues(true); base.setLabelOutlinePaint(java.awt.Color.WHITE); base.setLabelShadowPaint(java.awt.Color.WHITE); base.setMaximumLabelWidth( 0.25); // allow bigger labels by a bit (this will make the chart smaller) base.setInteriorGap(0.000); // allow stretch to compensate for the bigger label width base.setLabelBackgroundPaint(java.awt.Color.WHITE); base.setOutlinePaint(null); base.setBackgroundPaint(null); base.setShadowPaint(null); base.setSimpleLabels(false); // I think they're false anyway // change the look of the series title to be smaller StandardChartTheme theme = new StandardChartTheme("Hi"); TextTitle title = new TextTitle("Whatever", theme.getLargeFont()); title.setPaint(theme.getAxisLabelPaint()); title.setPosition(RectangleEdge.BOTTOM); baseChart.setTitle(title); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }
public ChartWindow(String title) { this.symbol = title; thisp = this; // initialize the main layout setTitle(title); mainpanel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); mainpanel.setLayout(gbl); // build a toolbar // add a plain status bar this.statusLine = new JLabel("Done"); this.getContentPane().add(statusLine, BorderLayout.SOUTH); statusLine.setBackground(new Color(0, 0, 0)); statusLine.setForeground(new Color(255, 255, 255)); statusLine.setOpaque(true); // x1 = new TimeSeries("symbol", FixedMillisecond.class); dataset1.addSeries(x1); System.out.println("Populated."); // chart = createChart(dataset1); System.out.println("constr."); // chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL); chart.setAntiAlias(false); chartPanel = new ChartPanel(chart); // int i = 0; gbc.anchor = gbc.NORTHWEST; gbc.fill = gbc.BOTH; gbc.weightx = 1; gbc.gridx = 0; gbc.weighty = 1; gbc.gridy = i; gbl.setConstraints(chartPanel, gbc); mainpanel.add(chartPanel); // System.out.println("add"); setVisible(true); setSize(new Dimension(400, 300)); // chartPanel.setPopupMenu(buildPopupMenu()); chartPanel.setMouseZoomable(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalZoom(true); chartPanel.setOpaque(true); chartPanel.setBackground(new Color(0, 0, 0)); this.getContentPane().add(mainpanel, BorderLayout.CENTER); this.setSize(600, 400); this.toFront(); this.show(); }
/** converts data into a candlestick chart */ public void convert() { chart.setAntiAlias(false); chartPanel.setChart(chart); }