List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis()
From source file:ruc.edu.window.DynamicDataDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title./* w w w. jav a 2s . c o m*/ */ public DynamicDataDemo2(final String title) { super(title); this.series1 = new TimeSeries("Random 1"); this.series2 = new TimeSeries("Random 2"); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1); final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.setDomainPannable(true); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); //axis.setAutoRangeMinimumSize(600000.0); axis.setFixedAutoRange(5000.0); // 60 seconds plot.setDataset(1, dataset2); //final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); /// rangeAxis2.setAutoRangeIncludesZero(false); plot.setRenderer(0, new DefaultXYItemRenderer()); plot.setRenderer(1, new DefaultXYItemRenderer()); //plot.setRangeAxis(1, rangeAxis2); plot.mapDatasetToRangeAxis(1, 0); plot.getRenderer().setSeriesPaint(0, new Color(91, 155, 213)); plot.getRenderer(1).setSeriesPaint(0, Color.BLUE); XYLineAndShapeRenderer render2 = new XYLineAndShapeRenderer() { Stroke soild = new BasicStroke(2.0f); Stroke dashed = new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f); @Override public Stroke getItemStroke(int row, int column) { return dashed; } }; plot.setRenderer(1, render2); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add To Series 1"); button1.setActionCommand("ADD_DATA_1"); button1.addActionListener(this); final JButton button2 = new JButton("Add To Series 2"); button2.setActionCommand("ADD_DATA_2"); button2.addActionListener(this); final JButton button3 = new JButton("Add To Both"); button3.setActionCommand("ADD_BOTH"); button3.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:com.charts.ThreeMonthChart.java
public ThreeMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/* ww w . j a v a 2s . c om*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:arduinoserialread.SerialRead.java
private void initGUI() { // init the frame frame.setTitle("Arduino Serial Read"); frame.setBounds(100, 100, 600, 500); frame.setMinimumSize(new Dimension(600, 500)); frame.setLocationRelativeTo(null);/*from w ww . j av a2 s . com*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // init control panel JPanel ctrlPanel = new JPanel(); ctrlPanel.setLayout(new FlowLayout()); // init the serial connection panel serialCOM = new SerialConnectionPanel(); ctrlPanel.add(serialCOM); frame.getContentPane().add(ctrlPanel, BorderLayout.SOUTH); // init the connection status ConnectionStatus connectionStatus = new ConnectionStatus(); ctrlPanel.add(connectionStatus); // init connect and disconnect button connect = new JButton("connect"); ctrlPanel.add(connect); disconnect = new JButton("disconnect"); ctrlPanel.add(disconnect); // init real time chart TimeSeries series = new TimeSeries("DATA"); DateAxis timeAxis = new DateAxis("Time"); dataset = new TimeSeriesCollection(series); NumberAxis rangeAxis = new NumberAxis("Data"); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRange(true); XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis, new StandardXYItemRenderer()); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.getRenderer().setSeriesPaint(0, new Color(0, 142, 192)); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setFixedAutoRange(30000.0); // 30 seconds // init the JFreeChart JFreeChart chart = new JFreeChart("Real-Time Data Chart", plot); chart.setBorderPaint(Color.lightGray); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); chart.removeLegend(); // add real time chart to the frame ChartPanel chartPanel = new ChartPanel(chart); frame.getContentPane().add(chartPanel, BorderLayout.CENTER); }
From source file:com.charts.OneMonthChart.java
public OneMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/*ww w . j a v a 2 s.c o m*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setVerticalTickLabels(true); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM-dd")); xAxis.setAutoTickUnitSelection(false); xAxis.setAutoRange(false); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:guineu.util.dialogs.AxesSetupDialog.java
/** * Constructor//from w w w . ja v a2s .c om */ public AxesSetupDialog(XYPlot plot) { // Make dialog modal super(GuineuCore.getDesktop().getMainFrame(), true); xAxis = plot.getDomainAxis(); yAxis = plot.getRangeAxis(); NumberFormat defaultFormatter = NumberFormat.getNumberInstance(); NumberFormat xAxisFormatter = defaultFormatter; if (xAxis instanceof NumberAxis) { xAxisFormatter = ((NumberAxis) xAxis).getNumberFormatOverride(); } NumberFormat yAxisFormatter = defaultFormatter; if (yAxis instanceof NumberAxis) { yAxisFormatter = ((NumberAxis) yAxis).getNumberFormatOverride(); } // Create labels and fields JLabel lblXTitle = new JLabel(xAxis.getLabel()); JLabel lblXAutoRange = new JLabel("Auto range"); JLabel lblXMin = new JLabel("Minimum"); JLabel lblXMax = new JLabel("Maximum"); JLabel lblXAutoTick = new JLabel("Auto tick size"); JLabel lblXTick = new JLabel("Tick size"); JLabel lblYTitle = new JLabel(yAxis.getLabel()); JLabel lblYAutoRange = new JLabel("Auto range"); JLabel lblYMin = new JLabel("Minimum"); JLabel lblYMax = new JLabel("Maximum"); JLabel lblYAutoTick = new JLabel("Auto tick size"); JLabel lblYTick = new JLabel("Tick size"); checkXAutoRange = new JCheckBox(); checkXAutoRange.addActionListener(this); checkXAutoTick = new JCheckBox(); checkXAutoTick.addActionListener(this); fieldXMin = new JFormattedTextField(xAxisFormatter); fieldXMax = new JFormattedTextField(xAxisFormatter); fieldXTick = new JFormattedTextField(xAxisFormatter); checkYAutoRange = new JCheckBox(); checkYAutoRange.addActionListener(this); checkYAutoTick = new JCheckBox(); checkYAutoTick.addActionListener(this); fieldYMin = new JFormattedTextField(yAxisFormatter); fieldYMax = new JFormattedTextField(yAxisFormatter); fieldYTick = new JFormattedTextField(yAxisFormatter); // Create a panel for labels and fields JPanel pnlLabelsAndFields = new JPanel(new GridLayout(0, 2)); pnlLabelsAndFields.add(lblXTitle); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblXAutoRange); pnlLabelsAndFields.add(checkXAutoRange); pnlLabelsAndFields.add(lblXMin); pnlLabelsAndFields.add(fieldXMin); pnlLabelsAndFields.add(lblXMax); pnlLabelsAndFields.add(fieldXMax); if (xAxis instanceof NumberAxis) { pnlLabelsAndFields.add(lblXAutoTick); pnlLabelsAndFields.add(checkXAutoTick); pnlLabelsAndFields.add(lblXTick); pnlLabelsAndFields.add(fieldXTick); } // Empty row pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblYTitle); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblYAutoRange); pnlLabelsAndFields.add(checkYAutoRange); pnlLabelsAndFields.add(lblYMin); pnlLabelsAndFields.add(fieldYMin); pnlLabelsAndFields.add(lblYMax); pnlLabelsAndFields.add(fieldYMax); if (yAxis instanceof NumberAxis) { pnlLabelsAndFields.add(lblYAutoTick); pnlLabelsAndFields.add(checkYAutoTick); pnlLabelsAndFields.add(lblYTick); pnlLabelsAndFields.add(fieldYTick); } // Create buttons JPanel pnlButtons = new JPanel(); btnOK = new JButton("OK"); btnOK.addActionListener(this); btnApply = new JButton("Apply"); btnApply.addActionListener(this); btnCancel = new JButton("Cancel"); btnCancel.addActionListener(this); pnlButtons.add(btnOK); pnlButtons.add(btnApply); pnlButtons.add(btnCancel); // Put everything into a main panel JPanel pnlAll = new JPanel(new BorderLayout()); pnlAll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); add(pnlAll); pnlAll.add(pnlLabelsAndFields, BorderLayout.CENTER); pnlAll.add(pnlButtons, BorderLayout.SOUTH); pack(); setTitle("Please set ranges for axes"); setResizable(false); setLocationRelativeTo(GuineuCore.getDesktop().getMainFrame()); getValuesToControls(); }
From source file:net.sf.mzmine.util.dialogs.AxesSetupDialog.java
/** * Constructor/* ww w .ja v a 2 s. c om*/ */ public AxesSetupDialog(XYPlot plot) { // Make dialog modal super(MZmineCore.getDesktop().getMainWindow(), true); xAxis = plot.getDomainAxis(); yAxis = plot.getRangeAxis(); NumberFormat defaultFormatter = NumberFormat.getNumberInstance(); NumberFormat xAxisFormatter = defaultFormatter; if (xAxis instanceof NumberAxis) xAxisFormatter = ((NumberAxis) xAxis).getNumberFormatOverride(); NumberFormat yAxisFormatter = defaultFormatter; if (yAxis instanceof NumberAxis) yAxisFormatter = ((NumberAxis) yAxis).getNumberFormatOverride(); // Create labels and fields JLabel lblXTitle = new JLabel(xAxis.getLabel()); JLabel lblXAutoRange = new JLabel("Auto range"); JLabel lblXMin = new JLabel("Minimum"); JLabel lblXMax = new JLabel("Maximum"); JLabel lblXAutoTick = new JLabel("Auto tick size"); JLabel lblXTick = new JLabel("Tick size"); JLabel lblYTitle = new JLabel(yAxis.getLabel()); JLabel lblYAutoRange = new JLabel("Auto range"); JLabel lblYMin = new JLabel("Minimum"); JLabel lblYMax = new JLabel("Maximum"); JLabel lblYAutoTick = new JLabel("Auto tick size"); JLabel lblYTick = new JLabel("Tick size"); checkXAutoRange = new JCheckBox(); checkXAutoRange.addActionListener(this); checkXAutoTick = new JCheckBox(); checkXAutoTick.addActionListener(this); fieldXMin = new JFormattedTextField(xAxisFormatter); fieldXMax = new JFormattedTextField(xAxisFormatter); fieldXTick = new JFormattedTextField(xAxisFormatter); checkYAutoRange = new JCheckBox(); checkYAutoRange.addActionListener(this); checkYAutoTick = new JCheckBox(); checkYAutoTick.addActionListener(this); fieldYMin = new JFormattedTextField(yAxisFormatter); fieldYMax = new JFormattedTextField(yAxisFormatter); fieldYTick = new JFormattedTextField(yAxisFormatter); // Create a panel for labels and fields JPanel pnlLabelsAndFields = new JPanel(new GridLayout(0, 2)); pnlLabelsAndFields.add(lblXTitle); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblXAutoRange); pnlLabelsAndFields.add(checkXAutoRange); pnlLabelsAndFields.add(lblXMin); pnlLabelsAndFields.add(fieldXMin); pnlLabelsAndFields.add(lblXMax); pnlLabelsAndFields.add(fieldXMax); if (xAxis instanceof NumberAxis) { pnlLabelsAndFields.add(lblXAutoTick); pnlLabelsAndFields.add(checkXAutoTick); pnlLabelsAndFields.add(lblXTick); pnlLabelsAndFields.add(fieldXTick); } // Empty row pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblYTitle); pnlLabelsAndFields.add(new JPanel()); pnlLabelsAndFields.add(lblYAutoRange); pnlLabelsAndFields.add(checkYAutoRange); pnlLabelsAndFields.add(lblYMin); pnlLabelsAndFields.add(fieldYMin); pnlLabelsAndFields.add(lblYMax); pnlLabelsAndFields.add(fieldYMax); if (yAxis instanceof NumberAxis) { pnlLabelsAndFields.add(lblYAutoTick); pnlLabelsAndFields.add(checkYAutoTick); pnlLabelsAndFields.add(lblYTick); pnlLabelsAndFields.add(fieldYTick); } // Create buttons JPanel pnlButtons = new JPanel(); btnOK = new JButton("OK"); btnOK.addActionListener(this); btnApply = new JButton("Apply"); btnApply.addActionListener(this); btnCancel = new JButton("Cancel"); btnCancel.addActionListener(this); pnlButtons.add(btnOK); pnlButtons.add(btnApply); pnlButtons.add(btnCancel); // Put everything into a main panel JPanel pnlAll = new JPanel(new BorderLayout()); pnlAll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); add(pnlAll); pnlAll.add(pnlLabelsAndFields, BorderLayout.CENTER); pnlAll.add(pnlButtons, BorderLayout.SOUTH); pack(); setTitle("Please set ranges for axes"); setResizable(false); setLocationRelativeTo(MZmineCore.getDesktop().getMainWindow()); getValuesToControls(); }
From source file:com.charts.SixMonthChart.java
public SixMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);//from ww w . j av a 2 s .c o m rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:serverrobot.DynamicGraph.java
public JFreeChart createChart(XYDataset dataset, String pos, double minRange, double maxRange) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(pos, "Time (ms)", "Displacement", dataset, true, true, false);//from w ww . j a v a 2 s. co m final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(new Color(232, 232, 232)); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.getRenderer().setSeriesPaint(0, Color.BLUE); plot.getRenderer().setSeriesPaint(1, Color.RED); ValueAxis axis = plot.getDomainAxis(); //axis.setAutoRange(true); axis.setFixedAutoRange(20000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setRange(minRange, maxRange); chart.setBackgroundPaint(Color.white); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo4.java
protected JFreeChart createChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset, PlotOrientation.VERTICAL, false, //!legendPanelOn, true, false);/* ww w. j a v a 2 s .c om*/ // then customise it a little... // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do")); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setRenderer(new ClusteredXYBarRenderer()); XYItemRenderer renderer = plot.getRenderer(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); return chart; }
From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java
/** Creates new form SQEHistoryPanel */ public SQEHistoryPanel() { historyChart = org.jfree.chart.ChartFactory.createStackedXYAreaChart(null, "Snapshot", "CodeDefects", perProjectDataSet, PlotOrientation.VERTICAL, false, true, false); historyChart.setBackgroundPaint(Color.WHITE); historyChart.getXYPlot().setRangeGridlinePaint(Color.BLACK); historyChart.getXYPlot().setDomainGridlinePaint(Color.BLACK); historyChart.getXYPlot().setBackgroundPaint(Color.WHITE); XYPlot plot = historyChart.getXYPlot(); plot.setForegroundAlpha(0.7f);/*w w w . j a v a2s.c o m*/ // plot.getRenderer(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects"); rangeAxis.setStrictValuesFlag(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(rangeAxis); StackedXYAreaRenderer2 categoryItemRenderer = new StackedXYAreaRenderer2(); //3D(); categoryItemRenderer.setSeriesPaint(0, Color.RED); categoryItemRenderer.setSeriesPaint(1, Color.ORANGE); categoryItemRenderer.setSeriesPaint(2, Color.YELLOW); plot.setRenderer(categoryItemRenderer); ChartPanel historyChartPanel = new ChartPanel(historyChart); historyChartPanel.setBorder(null); historyChartPanel.setPreferredSize(new Dimension(150, 200)); historyChartPanel.setBackground(Color.WHITE); initComponents(); historyView.setLayout(new BorderLayout()); historyView.add(historyChartPanel, BorderLayout.CENTER); JPanel selectorPanel = new JPanel(); selectorPanel.setOpaque(false); GroupLayout layout = new GroupLayout(selectorPanel); selectorPanel.setLayout(layout); // Turn on automatically adding gaps between components layout.setAutocreateGaps(true); // Turn on automatically creating gaps between components that touch // the edge of the container and the container. layout.setAutocreateContainerGaps(true); ParallelGroup horizontalParallelGroup = layout.createParallelGroup(GroupLayout.LEADING); SequentialGroup verticalSequentialGroup = layout.createSequentialGroup(); layout.setHorizontalGroup(layout.createSequentialGroup().add(horizontalParallelGroup)); layout.setVerticalGroup(verticalSequentialGroup); clearHistoryButton = new JButton(); clearHistoryButton.setEnabled(false); clearHistoryButton.setIcon(ImageUtilities .image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/codedefects/history/resources/trash.png"))); clearHistoryButton.setOpaque(false); clearHistoryButton.setFocusPainted(false); clearHistoryButton.setToolTipText( NbBundle.getBundle("org/nbheaven/sqe/codedefects/history/controlcenter/panels/Bundle") .getString("HINT_clear_button")); horizontalParallelGroup.add(clearHistoryButton); verticalSequentialGroup.add(clearHistoryButton); clearHistoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (null != activeHistory) { activeHistory.clear(); } } }); Component createVerticalStrut = Box.createVerticalStrut(10); horizontalParallelGroup.add(createVerticalStrut); verticalSequentialGroup.add(createVerticalStrut); for (final QualityProvider provider : SQEUtilities.getProviders()) { final JToggleButton providerButton = new JToggleButton(); providerButton.setIcon(provider.getIcon()); providerButton.setOpaque(false); providerButton.setFocusPainted(false); horizontalParallelGroup.add(providerButton); verticalSequentialGroup.add(providerButton); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (providerButton.isSelected()) { addSelectedProvider(provider); } else { removeSelectedProvider(provider); } updateView(); } }; providerButton.addActionListener(listener); addSelectedProvider(provider); providerButton.setSelected(true); } historyView.add(selectorPanel, BorderLayout.EAST); }