List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JFreeChart createStackedXYBarChart(XYDataset dataset, String title, String domainAxisLabel, String rangeAxisLabel, boolean legend) { DateAxis dateaxis = new DateAxis(domainAxisLabel); NumberAxis numberaxis = new NumberAxis(rangeAxisLabel); StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.10000000000000001D); XYPlot xyplot = new XYPlot(dataset, dateaxis, numberaxis, stackedxybarrenderer); JFreeChart jfreechart = new JFreeChart(title, UIConstants.H5_FONT, xyplot, legend); ChartUtilities.applyCurrentTheme(jfreechart); stackedxybarrenderer.setShadowVisible(false); stackedxybarrenderer.setDrawBarOutline(false); stackedxybarrenderer.setBarPainter(new StandardXYBarPainter()); stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator( "<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("###"))); xyplot.setBackgroundPaint(null);/*w w w . j a v a2 s .c o m*/ xyplot.setOutlinePaint(null); xyplot.setRangeGridlinePaint(UIConstants.INTEL_BORDER_GRAY); dateaxis.setLabelFont(UIConstants.H5_FONT); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); numberaxis.setRangeType(RangeType.POSITIVE); numberaxis.setLabelFont(UIConstants.H5_FONT); numberaxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0)); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return jfreechart; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createDailyLoginChart(int width, int height) { IntervalXYDataset dataset1 = getDailyLoginsDataSet(); IntervalXYDataset dataset2 = getDailySiteUserDataSet(); if ((dataset1 == null) || (dataset2 == null)) { return generateNoDataChart(width, height); }//from www. j a va 2 s . c o m // create plot ... XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setSeriesPaint(0, Color.RED); renderer1.setSeriesPaint(1, Color.BLUE); renderer1.setSeriesPaint(2, Color.RED); renderer1.setSeriesPaint(3, Color.BLUE); renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); BasicStroke dashLineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { 4 }, 0); renderer1.setSeriesStroke(2, dashLineStroke); renderer1.setSeriesStroke(3, dashLineStroke); DateAxis domainAxis = new DateAxis(""); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("yyyy-MM-dd"))); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); domainAxis.setVerticalTickLabels(true); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); NumberAxis rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesPaint(0, Color.GREEN); renderer2.setSeriesPaint(1, Color.BLACK); renderer2.setSeriesPaint(2, Color.CYAN); rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:qmul.align.AlignmentTester.java
/** * Plot a turn vs score chart with arbitrary subplots * //from w w w . j a v a 2 s . c o m * @param scores1 * @param title */ private void plotScores(String title, List<Double>... scores) { ApplicationFrame af = new ApplicationFrame(title); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis()); plot.setGap(10.0); for (int i = 0; i < scores.length; i++) { final XYSeries series = new XYSeries("Coherence scores " + i); for (int x = 0; x < scores[i].size(); x++) { series.add(x, scores[i].get(x)); } XYSeriesCollection data = new XYSeriesCollection(series); XYPlot subplot = new XYPlot(data, null, new NumberAxis(), new StandardXYItemRenderer()); subplot.setRangeAxisLocation(i == 0 ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_LEFT); plot.add(subplot, 1); } plot.setOrientation(PlotOrientation.VERTICAL); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(1000, 500)); af.setContentPane(chartPanel); af.pack(); RefineryUtilities.centerFrameOnScreen(af); af.setVisible(true); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a combined and overlaid chart. * <p>/* ww w . j ava2s .co m*/ * Note: from version 0.9.10, the overlaid chart is no longer supported (you can achieve * the same result using a regular XYPlot with multiple datasets and renderers). * * @return a combined and overlaid chart. */ public JFreeChart createCombinedAndOverlaidChart1() { // create a default chart based on some sample data... final String title = this.resources.getString("combined.combined-overlaid.title"); final String subtitleStr = this.resources.getString("combined.combined-overlaid.subtitle"); final String domain = this.resources.getString("combined.combined-overlaid.domain"); final String[] ranges = this.resources.getStringArray("combined.combined-overlaid.ranges"); final TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries(); final TimeSeries mav = MovingAverage.createMovingAverage(jpy, "30 Day Moving Average", 30, 30); final TimeSeriesCollection dataset0 = new TimeSeriesCollection(); dataset0.addSeries(jpy); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(); dataset1.addSeries(jpy); dataset1.addSeries(mav); final DefaultHighLowDataset highLowDataset = DemoDatasetFactory.createHighLowDataset(); final XYDataset highLowDatasetMA = MovingAverage.createMovingAverage(highLowDataset, " (MA)", 5 * 24 * 60 * 60 * 1000L, 5 * 24 * 60 * 60 * 1000L); // make one vertical axis for each (vertical) chart final NumberAxis[] valueAxis = new NumberAxis[3]; for (int i = 0; i < valueAxis.length; i++) { valueAxis[i] = new NumberAxis(ranges[i]); if (i <= 1) { valueAxis[i].setAutoRangeIncludesZero(false); // override default } } // create CombinedPlot... final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new DateAxis(domain)); final int[] weight = { 1, 2, 2 }; // add subplot1... final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final XYPlot subplot1 = new XYPlot(dataset0, null, new NumberAxis(ranges[0]), renderer1); final NumberAxis axis1 = (NumberAxis) subplot1.getRangeAxis(); axis1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); axis1.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); axis1.setAutoRangeIncludesZero(false); parent.add(subplot1, weight[0]); // add subplot2 (an overlaid plot)... final XYPlot subplot2 = new XYPlot(dataset0, null, new NumberAxis(ranges[1]), new StandardXYItemRenderer()); final NumberAxis axis2 = (NumberAxis) subplot2.getRangeAxis(); axis2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); axis2.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); axis2.setAutoRangeIncludesZero(false); subplot2.setDataset(1, dataset1); subplot2.setRenderer(1, new StandardXYItemRenderer()); parent.add(subplot2, weight[1]); // add subplot3 (an overlaid plot)... final XYItemRenderer renderer3 = new HighLowRenderer(); final XYPlot subplot3 = new XYPlot(highLowDataset, null, new NumberAxis(ranges[2]), renderer3); final NumberAxis axis3 = (NumberAxis) subplot3.getRangeAxis(); axis3.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); axis3.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); axis3.setAutoRangeIncludesZero(false); subplot3.setDataset(1, highLowDatasetMA); subplot3.setRenderer(1, new StandardXYItemRenderer()); parent.add(subplot3, weight[2]); // now create the master JFreeChart object final JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), parent, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 10)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }
From source file:beproject.MainGUI.java
void createTimeLine() throws SQLException { TimeSeriesCollection dataset = new TimeSeriesCollection(); getTimeLineData(dataset);/*from ww w. j a v a2 s . com*/ DateAxis domain = new DateAxis("Time"); NumberAxis range = new NumberAxis("Tweet Count"); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesPaint(1, Color.BLUE); renderer.setSeriesStroke(0, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer.setSeriesStroke(1, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); XYPlot plot = new XYPlot(dataset, domain, range, renderer); domain.setAutoRange(true); domain.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2, Regression.sdf)); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setTickLabelsVisible(true); range.setTickLabelsVisible(true); plot.setDomainGridlinesVisible(false); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setBaseItemLabelsVisible(true); JFreeChart liveTweetAnalysisChart = new JFreeChart("Rate of tweets per hour", new Font("Tahoma", Font.BOLD, 24), plot, true); liveTweetAnalysisChart.setBorderVisible(false); ChartUtilities.applyCurrentTheme(liveTweetAnalysisChart); domain.setTickLabelInsets(RectangleInsets.ZERO_INSETS); range.setTickMarksVisible(false); range.setTickLabelInsets(RectangleInsets.ZERO_INSETS); domain.setTickMarksVisible(false); liveTweetAnalysisChart.setPadding(RectangleInsets.ZERO_INSETS); ChartPanel liveTweetAnalysisChartPanel = new ChartPanel(liveTweetAnalysisChart, true); liveTweetAnalysisChartPanel.setBorder(null); if (timeLineChart == null) { timeLineChart = liveTweetAnalysisChartPanel; } else { timeLinePanel.remove(timeLineChart); timeLineChart = liveTweetAnalysisChartPanel; } timeLinePanel.add(timeLineChart); timeLinePanel.validate(); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Displays an XY chart that is periodically updated by a background thread. This is to * demonstrate the event notification system that automatically updates charts as required. * * @return a chart./*w ww . ja v a 2s .com*/ */ public JFreeChart createCombinedAndOverlaidDynamicXYChart() { // chart title and axis labels... final String title = this.resources.getString("combined.dynamic.title"); final String subtitleStr = this.resources.getString("combined.dynamic.subtitle"); final String domainAxisLabel = this.resources.getString("combined.dynamic.domain"); final String[] ranges = this.resources.getStringArray("combined.dynamic.ranges"); // setup sample base 2-series dataset final SampleXYDataset data = new SampleXYDataset(); // create some SubSeriesDatasets and CombinedDatasets to test events final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); final CombinedDataset combinedData = new CombinedDataset(); combinedData.add(series0); combinedData.add(series1); // create common time axis final NumberAxis timeAxis = new NumberAxis(domainAxisLabel); timeAxis.setTickMarksVisible(true); timeAxis.setAutoRangeIncludesZero(false); // make one vertical axis for each (vertical) chart final NumberAxis[] valueAxis = new NumberAxis[4]; for (int i = 0; i < valueAxis.length; i++) { valueAxis[i] = new NumberAxis(ranges[i]); valueAxis[i].setAutoRangeIncludesZero(false); } final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(timeAxis); // add subplot1... final XYItemRenderer renderer0 = new StandardXYItemRenderer(); final XYPlot subplot0 = new XYPlot(series0, null, valueAxis[0], renderer0); plot.add(subplot0, 1); // add subplot2... final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final XYPlot subplot1 = new XYPlot(series1, null, valueAxis[1], renderer1); plot.add(subplot1, 1); // add subplot3... final XYPlot subplot2 = new XYPlot(series0, null, valueAxis[2], new StandardXYItemRenderer()); subplot2.setDataset(1, series1); subplot2.setRenderer(1, new StandardXYItemRenderer()); plot.add(subplot2, 1); // add subplot4... final XYItemRenderer renderer3 = new StandardXYItemRenderer(); final XYPlot subplot3 = new XYPlot(data, null, valueAxis[3], renderer3); plot.add(subplot3, 1); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.cyan)); // setup thread to update base Dataset final SampleXYDatasetThread update = new SampleXYDatasetThread(data); final Thread thread = new Thread(update); thread.start(); return chart; }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
/** * Creates a chart.//from w w w. j a va 2s . com * * @return a chart. */ private JFreeChart createPriceVolumeChart(XYDataset priceDataset, XYDataset volumeDataset) { final String title = getBestStockName(); final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date")); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); final NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_Price")); rangeAxis1.setAutoRangeIncludesZero(false); // override default rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars DecimalFormat format = new DecimalFormat("0.00#"); rangeAxis1.setNumberFormatOverride(format); XYPlot plot = new XYPlot(priceDataset, timeAxis, rangeAxis1, null); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#"))); plot.setRenderer(0, renderer1); final NumberAxis rangeAxis2 = new NumberAxis("Volume"); rangeAxis2.setUpperMargin(1.00); // to leave room for price line plot.setRangeAxis(1, rangeAxis2); plot.setDataset(1, volumeDataset); plot.mapDatasetToRangeAxis(1, 1); XYBarRenderer renderer2 = new XYBarRenderer(0.20); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); plot.setRenderer(1, renderer2); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(timeAxis); cplot.add(plot, 1); cplot.setGap(8.0); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, cplot, true); org.yccheok.jstock.charting.Utils.applyChartThemeEx(chart); // Only do it after applying chart theme. org.yccheok.jstock.charting.Utils.setPriceSeriesPaint(renderer1); org.yccheok.jstock.charting.Utils.setVolumeSeriesPaint(renderer2); // Handle zooming event. chart.addChangeListener(this.getChartChangeListner()); return chart; }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java
private JFreeChart updateBubbleChartChartWithCustUserData( Set<QuantDiseaseGroupsComparison> selectedComparisonList) { tooltipsProtNumberMap.clear();/*w w w . java 2 s. c o m*/ DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset(); int counter = 0; int upper = -1; boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly(); if (userCustomizedComparison.getComparProtsMap().size() > upper) { upper = userCustomizedComparison.getComparProtsMap().size(); } for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { if (significantOnly) { int upperCounter = 0; for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) { if (qp == null) { continue; } if (qp.getSignificantTrindCategory() == 2) { continue; } upperCounter++; } if (upperCounter > upper) { upper = upperCounter; } } else { if (qc.getComparProtsMap() == null) { System.out.println("null qc " + qc.getComparisonHeader()); } if (qc.getComparProtsMap().size() > upper) { upper = qc.getComparProtsMap().size(); } } } final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>(); Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor, new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE }; double[] tempWidthValue = new double[8]; double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI }; seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE }); defaultxyzdataset.addSeries(" ", seriesValuesI); for (String key : userCustomizedComparison.getComparProtsMap().keySet()) { userCustomizedComparison.getComparProtsMap().get(key).updateLabelLayout(); { tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key) .getSignificantTrindCategory() + 1] + 1; } } int length = 0; if (upper < 10) { upper = 10; } double[] tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(userCustomizedComparison.getComparisonHeader(), tooltipNumbess); for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { tempWidthValue[z] = scaleValues(tempWidthValue[z], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } double[] yAxisValue = new double[length]; double[] xAxisValue = new double[length]; double[] widthValue = new double[length]; Color[] serColorArr = new Color[length]; length = 0; for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { xAxisValue[length] = z; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[z]; serColorArr[length] = dataColor[z]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(++counter, serColorArr); double[][] seriesValues = { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(userCustomizedComparison.getComparisonHeader(), seriesValues); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { tempWidthValue = new double[8]; if (qc.getComparProtsMap() == null) { continue; } for (String key : qc.getComparProtsMap().keySet()) { qc.getComparProtsMap().get(key).updateLabelLayout(); if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2 || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) { tempWidthValue[3] = 0; tempWidthValue[6] = 0; } else { tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] + 1; } } if (tempWidthValue[3] > 0 && tempWidthValue[6] >= 0) { stableColor = new Color(1, 141, 244); } else { stableColor = Color.decode("#b5babb"); } tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6]; tempWidthValue[6] = 0; dataColor[3] = stableColor; length = 0; if (upper < 10) { upper = 10; } tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess); for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } yAxisValue = new double[length]; xAxisValue = new double[length]; widthValue = new double[length]; serColorArr = new Color[length]; length = 0; for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { xAxisValue[length] = x; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[x]; serColorArr[length] = dataColor[x]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(counter + 1, serColorArr); seriesValues = new double[][] { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues); counter++; } double[] yAxisValueII = new double[0]; double[] xAxisValueII = new double[0]; double[] widthValueII = new double[0]; seriousColorMap.put(counter + 1, new Color[] {}); double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII }; defaultxyzdataset.addSeries(" ", seriesValuesII); final Color[] labelsColor = new Color[] { Color.WHITE, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.WHITE }; Font font = new Font("Verdana", Font.BOLD, 13); SymbolAxis yAxis = new SymbolAxis(null, new String[] { " ", "Decreased", " ", "Equal", " ", "Increased", " " }) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labelsColor.length) { x = 0; } return labelsColor[x++]; } }; yAxis.setAutoRangeStickyZero(true); yAxis.setFixedAutoRange(8); yAxis.setTickLabelFont(font); yAxis.setGridBandsVisible(false); yAxis.setAxisLinePaint(Color.LIGHT_GRAY); yAxis.setTickMarksVisible(false); yAxis.setUpperBound(6); String[] xAxisLabels = new String[selectedComparisonList.size() + 3]; xAxisLabels[0] = " "; final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 3]; int x = 0; int maxLength = -1; //init labels color String updatedHeader = userCustomizedComparison.getComparisonHeader().split(" / ")[0].split("\n")[0] + " / " + userCustomizedComparison.getComparisonHeader().split(" / ")[1].split("\n")[0] + ""; diseaseGroupslabelsColor[0] = Color.WHITE; diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get("UserData"); xAxisLabels[x + 1] = updatedHeader + " (" + userCustomizedComparison.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[++x].length(); } for (QuantDiseaseGroupsComparison comp : selectedComparisonList) { String header = comp.getComparisonHeader(); updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0] + ""; xAxisLabels[x + 1] = updatedHeader + " (" + comp.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[x + 1].length(); } diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]); x++; } xAxisLabels[x + 1] = " "; SymbolAxis xAxis; final boolean finalNum; finalNum = maxLength > 30 && selectedComparisonList.size() > 4; xAxis = new SymbolAxis(null, xAxisLabels) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= diseaseGroupslabelsColor.length) { x = 0; } return diseaseGroupslabelsColor[x++]; } private final boolean localfinal = finalNum; @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { if (localfinal) { setVerticalTickLabels(localfinal); return super.refreshTicksHorizontal(g2, dataArea, edge); } List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue) + " "; } else { tickLabel = valueToString(currentTickValue) + " "; } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { setVerticalTickLabels(true); } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor; TextAnchor rotationAnchor; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = 76.5; } else { angle = -76.5; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks; } }; // } xAxis.setTickLabelFont(font); xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20)); xAxis.setAutoRangeStickyZero(true); xAxis.setAutoRangeStickyZero(true); xAxis.setTickMarksVisible(false); xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1); xAxis.setGridBandsVisible(false); xAxis.setAxisLinePaint(Color.LIGHT_GRAY); int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS; XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) { private int counter = 0; private int localSerious = -1; private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap; @Override public Paint getSeriesPaint(int series) { if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) { counter = 0; isNewImge = false; } localSerious = series; Color c = localSeriousColorMap.get(series)[counter]; counter++; return c; } }; XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) { @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) { try { if (!ticks.isEmpty()) { ticks.remove(0); } if (!ticks.isEmpty()) { ticks.remove(ticks.size() - 1); } } catch (Exception e) { } super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates. } // private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")}; // // private final Font font = new Font("Verdana", Font.PLAIN, 12); // private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."}; // // @Override // public LegendItemCollection getLegendItems() { // LegendItemCollection legendItemCollection = new LegendItemCollection(); // for (int i = 0; i < labelsColor.length; i++) { // LegendItem item = new LegendItem(labels[i], labelsColor[i]); // item.setLabelFont(font); // legendItemCollection.add(item); // // } // // return legendItemCollection;//To change body of generated methods, choose Tools | Templates. // } }; JFreeChart generatedChart = new JFreeChart(xyplot) { }; xyplot.setOutlineVisible(false); LegendTitle legend = generatedChart.getLegend(); legend.setVisible(false); xyplot.setBackgroundPaint(Color.WHITE); generatedChart.setBackgroundPaint(Color.WHITE); generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0)); Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart); return generatedChart; }
From source file:com.att.aro.diagnostics.GraphPanel.java
/** * Returns a XYPlot for GPS info/*from w w w . ja va2 s. c o m*/ * * @return XYPlot. */ private static XYPlot createBarPlot(Color color) { // Create renderer XYBarRenderer barRenderer = new XYBarRenderer(); barRenderer.setDrawBarOutline(false); barRenderer.setUseYInterval(true); barRenderer.setBasePaint(color); barRenderer.setAutoPopulateSeriesPaint(false); barRenderer.setShadowVisible(false); barRenderer.setGradientPaintTransformer(null); XYBarPainter painter = new StandardXYBarPainter(); barRenderer.setBarPainter(painter); // Create result plot XYPlot barPlot = new XYPlot(null, null, new NumberAxis(), barRenderer); barPlot.getRangeAxis().setVisible(false); return barPlot; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a scatter plot with default settings. The chart object * returned by this method uses an {@link XYPlot} instance as the plot, * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis} * as the range axis, and an {@link XYLineAndShapeRenderer} as the * renderer. /* w w w . j a v a2 s . com*/ * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A scatter plot. */ public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }