List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis
public NumberAxis(String label)
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 www . ja va 2s . co 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:com.charts.TenYearChart.java
public TenYearChart(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.setBaseToolTipGenerator(// w w w .j a v a 2 s . c om new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer.setDrawVolume(false); 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(900, 400)); 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(); 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:org.jfree.chart.demo.MemoryUsageDemo.java
public MemoryUsageDemo(int i) { super(new BorderLayout()); total = new TimeSeries("Total Memory"); total.setMaximumItemAge(i);/*w ww . j av a 2 s. c om*/ free = new TimeSeries("Free Memory"); free.setMaximumItemAge(i); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(total); timeseriescollection.addSeries(free); DateAxis dateaxis = new DateAxis("Time"); NumberAxis numberaxis = new NumberAxis("Memory"); dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateaxis.setLabelFont(new Font("SansSerif", 0, 14)); numberaxis.setLabelFont(new Font("SansSerif", 0, 14)); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.red); xylineandshaperenderer.setSeriesPaint(1, Color.green); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2)); xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2)); XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); dateaxis.setAutoRange(true); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); dateaxis.setTickLabelsVisible(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true); jfreechart.setBackgroundPaint(Color.white); ChartPanel chartpanel = new ChartPanel(jfreechart, true); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(chartpanel); }
From source file:net.sf.profiler4j.console.AllocDiffPanel.java
public AllocDiffPanel(int maxAgeMillis) { super(new BorderLayout()); totalSeries = new TimeSeries("Allocs/Sec", Millisecond.class); totalSeries.setMaximumItemAge(maxAgeMillis); TimeSeriesCollection seriesCollection = new TimeSeriesCollection(); seriesCollection.addSeries(totalSeries); NumberAxis numberAxis = new NumberAxis("Allocs/Sec"); numberAxis.setLabelFont(new Font("SansSerif", 0, 14)); numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); DateAxis dateAxis = new DateAxis("Time"); dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateAxis.setLabelFont(new Font("SansSerif", 0, 14)); dateAxis.setAutoRange(true);/*from w w w. j a v a 2 s .com*/ dateAxis.setLowerMargin(0); dateAxis.setUpperMargin(0); dateAxis.setTickLabelsVisible(true); dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); lineRenderer.setSeriesPaint(0, Color.RED); lineRenderer.setSeriesPaint(1, Color.GREEN.darker()); lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer); xyplot.setBackgroundPaint(Color.WHITE); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); JFreeChart chart = new JFreeChart("Object Allocactions in Remote JVM", new Font("SansSerif", Font.PLAIN, 18), xyplot, true); chart.setBackgroundPaint(Color.white); ChartPanel panel = new ChartPanel(chart); panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY))); add(panel); setBorder(createEmptyBorder(8, 8, 8, 8)); }
From source file:bzstats.chart.KillRatioHistoryChart.java
protected JFreeChart getChart() { DefaultTableXYDataset dataset = new DefaultTableXYDataset(); fillDataset(dataset);//w w w .j av a 2 s. c o m XYPlot plot = new XYPlot(); NumberAxis xaxis = new NumberAxis("Time"); xaxis.setTickLabelsVisible(false); NumberAxis yaxis = new NumberAxis("Killratio"); plot.setDomainAxis(xaxis); plot.setRangeAxis(yaxis); plot.setDataset(dataset); plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES)); JFreeChart chart = new JFreeChart("Killratio", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.addSubtitle(new TextTitle("kills/deaths")); chart.setBackgroundPaint(Color.white); return chart; }
From source file:org.gwaspi.reports.PlinkReportLoader.java
public static CombinedRangeXYPlot loadAssocUnadjLogPvsPos(File plinkReport, Set<String> redMarkersHS) throws IOException { XYSeriesCollection chrData = new XYSeriesCollection(); NumberAxis sharedAxis = new NumberAxis("-log?(P)"); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(sharedAxis); combinedPlot.setGap(0);//from ww w . j ava 2 s. com XYSeries series1 = null; XYSeries series2 = null; FileReader inputFileReader = null; BufferedReader inputBufferReader = null; String tempChr = null; try { inputFileReader = new FileReader(plinkReport); inputBufferReader = new BufferedReader(inputFileReader); // Getting data from file and subdividing to series all points by chromosome String l; tempChr = ""; String header = inputBufferReader.readLine(); int count = 0; while ((l = inputBufferReader.readLine()) != null) { if (count % 10000 == 0) { log.info("loadAssocUnadjLogPvsPos -> reader count: {}", count); } count++; l = l.trim().replaceAll("\\s+", ","); String[] cVals = l.split(","); String markerId = cVals[1]; int position = Integer.parseInt(cVals[2]); String s_pVal = cVals[8]; if (!s_pVal.equals("NA")) { double logPValue = Math.abs(Math.log(Double.parseDouble(s_pVal)) / Math.log(10)); if (cVals[0].toString().equals(tempChr)) { if (redMarkersHS.contains(markerId)) { series2.add(position, logPValue); } else { series1.add(position, logPValue); } labeler.put(tempChr + "_" + position, markerId); } else { if (!tempChr.isEmpty()) { // SKIP FIRST TIME (NO DATA YET!) chrData.addSeries(series1); chrData.addSeries(series2); appendToCombinedRangePlot(combinedPlot, tempChr, chrData); } tempChr = cVals[0]; series1 = new XYSeries("Imputed"); series2 = new XYSeries("Observed"); labeler.put(tempChr + "_" + position, markerId); if (redMarkersHS.contains(markerId)) { series2.add(position, logPValue); } else { series1.add(position, logPValue); } } } } } finally { if (inputBufferReader != null) { inputBufferReader.close(); } else if (inputFileReader != null) { inputFileReader.close(); } } chrData.addSeries(series1); chrData.addSeries(series2); appendToCombinedRangePlot(combinedPlot, tempChr, chrData); // ADD LAST CHR TO PLOT return combinedPlot; }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.SimpleScatterPlot.java
public SimpleScatterPlot(double[] xValues, double[] yValues, double[] colors, String xLabel, String yLabel) { super(null, true); setBackground(Color.white);//w w w . j av a2 s .co m 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); }
From source file:org.shredzone.bullshitcharts.chart.BarChartGenerator.java
@Override public Plot generate() { LineDatasetCreator dataset = new LineDatasetCreator(); dataset.setTendency(getTendency());/*ww w . jav a 2 s . c om*/ dataset.setNumberOfValues(getResolution()); dataset.setAmplitude(getAmplitude()); CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n catAxis.setLowerMargin(0.0d); catAxis.setUpperMargin(0.0d); catAxis.setTickMarksVisible(false); catAxis.setTickLabelsVisible(false); ValueAxis valAxis = new NumberAxis(getValue("y", "Value")); valAxis.setRange(new Range(0.0d, 1.05d)); valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); valAxis.setTickMarksVisible(false); valAxis.setTickLabelsVisible(false); BarRenderer3D renderer = new BarRenderer3D(); CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); return plot; }
From source file:statistic.graph.XYChart.java
public XYChart(String title, String xAxisLabel, String yAxis, XYSeriesCollection collection, boolean linear) { super(title, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), true); this.collection = collection; setBackgroundPaint(Color.WHITE); setTitle(title);/*from w ww . j ava 2 s .com*/ plot = (XYPlot) getPlot(); plot.setDataset(collection); if (linear) { plot.setRenderer(new DefaultXYItemRenderer()); } else { plot.setRenderer(new XYStepRenderer()); } plot.setOrientation(PlotOrientation.VERTICAL); initXAxis(xAxisLabel); plot.setRangeAxis(new NumberAxis(yAxis)); plot.setBackgroundPaint(Color.LIGHT_GRAY); 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); }
From source file:org.shredzone.bullshitcharts.chart.LineChartGenerator.java
@Override public Plot generate() { LineDatasetCreator dataset = new LineDatasetCreator(); dataset.setTendency(getTendency());/*from w w w .j av a 2s .c om*/ dataset.setNumberOfValues(getResolution()); dataset.setAmplitude(getAmplitude()); CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n catAxis.setLowerMargin(0.0d); catAxis.setUpperMargin(0.0d); catAxis.setTickMarksVisible(false); catAxis.setTickLabelsVisible(false); ValueAxis valAxis = new NumberAxis(getValue("y", "Value")); valAxis.setRange(new Range(0.0d, 1.05d)); valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); valAxis.setTickMarksVisible(false); valAxis.setTickLabelsVisible(false); LineAndShapeRenderer renderer = new LineRenderer3D(); renderer.setBaseShapesVisible(false); // renderer.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER)); CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); return plot; }