List of usage examples for java.awt BasicStroke BasicStroke
public BasicStroke(float width)
From source file:net.sf.jasperreports.chartthemes.provider.LineBorderProvider.java
@Override public BlockFrame getBlockFrame() { RectangleInsets borderInsets = insets == null ? new RectangleInsets(1.0, 1.0, 1.0, 1.0) : insets; Stroke borderStroke = lineStroke == null ? new BasicStroke(1.0f) : lineStroke; Paint borderPaint = paint == null ? null : paint.getPaint(); if (borderPaint == null) { borderPaint = Color.BLACK; }/*from w w w.jav a2 s . c o m*/ return new LineBorder(borderPaint, borderStroke, borderInsets); }
From source file:com.che.software.testato.util.jfreechart.LineChartGraphistUtil.java
/** * Colorized and transforms a given JFreeChart. * //from w ww .jav a 2s. c o m * @author Clement HELIOU (clement.heliou@che-software.com). * @param lineChart the given chart. * @param maxAbscissaValue the max abscissa value of the chart. * @param xValues the x axis values list. * @param yValues the y axis values list. * @param xExcludedValues the x axis excluded values. * @param yExcludedValues the y axis excluded values. * @return the transformed chart. * @since August, 2011. */ public static JFreeChart getColorizedChartFromChart(JFreeChart lineChart, double maxAbscissaValue, List<MatrixResult> xValues, List<MatrixResult> yValues, List<MatrixResult> xExcludedValues, List<MatrixResult> yExcludedValues) { LOGGER.debug("getColorizedChartFromChart()."); lineChart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) lineChart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesStroke(2, new BasicStroke(2)); renderer.setSeriesStroke(3, new BasicStroke(2)); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesShapesVisible(3, false); renderer.setSeriesPaint(0, ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); renderer.setSeriesPaint(1, ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); renderer.setSeriesPaint(2, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); renderer.setSeriesPaint(3, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.setRenderer(renderer); XYTextAnnotation low = new XYTextAnnotation( LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_LOW_NAME), (0.5 * maxAbscissaValue) - 1, maxAbscissaValue + 1), medium = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_MEDIUM_NAME), (1.5 * maxAbscissaValue) - 2, maxAbscissaValue + 1), high = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_HIGH_NAME), 1.5 * maxAbscissaValue, maxAbscissaValue - 2); low.setFont(ColorUtil.TITLE_FONT); medium.setFont(ColorUtil.TITLE_FONT); high.setFont(ColorUtil.TITLE_FONT); low.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); medium.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); high.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.addAnnotation(low); plot.addAnnotation(medium); plot.addAnnotation(high); for (int i = 0; i < xValues.size(); i++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xValues.get(i).getScriptLabel(), (yValues.get(i).getPercentage() * 100), (xValues.get(i).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); plot.addAnnotation(itemLabel); } if (null != xExcludedValues) { for (int j = 0; j < xExcludedValues.size(); j++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xExcludedValues.get(j).getScriptLabel(), (yExcludedValues.get(j).getPercentage() * 100), (xExcludedValues.get(j).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); plot.addAnnotation(itemLabel); } } return lineChart; }
From source file:statUtil.TurnMovementPlot.java
public TurnMovementPlot(String title) throws IOException { super(title); Data data = CSVData.getCSVData(TURN_CSV_LOG); JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", XYDatasetGenerator.generateXYDataset(data.csvData)); final XYPlot xyPlot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesStroke(0, new BasicStroke(3f)); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f); renderer.setSeriesShape(1, cross);/*from w w w .j a va2 s.c o m*/ xyPlot.setRenderer(renderer); xyPlot.setQuadrantOrigin(new Point(0, 0)); int i = 0; for (Double[] csvRow : data.csvData) { if (i % 20 == 1) { final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0], csvRow[1]); annotation.setFont(new Font("SansSerif", Font.PLAIN, 10)); xyPlot.addAnnotation(annotation); } i++; } int width = (int) Math.round(data.maxX - data.minX) + 50; int height = (int) Math.round(data.maxY - data.minY) + 50; ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(width, height)); setContentPane(chartPanel); File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png"); ChartUtilities.saveChartAsPNG(XYChart, chart, width, height); }
From source file:network.Draw.java
@Override public void run() { JFrame frame = new JFrame(); frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override/*w w w .j ava 2 s . c o m*/ public void windowClosing(java.awt.event.WindowEvent windowEvent) { isRun = false; } }); while (isRun) { JFreeChart xylineChart; if (method == 0) { System.out.println("hi"); xylineChart = ChartFactory.createXYLineChart("Tempreture", "Time", "Tempreture", createDataset(0), PlotOrientation.VERTICAL, true, true, false); } else { System.out.println("hi"); xylineChart = ChartFactory.createXYLineChart("Tempreture", "Time", "Tempreture", createDataset(1), PlotOrientation.VERTICAL, true, true, false); } final XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); plot.setRenderer(renderer); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setSize(700, 500); frame.getContentPane().removeAll(); ChartPanel chartPanel = new ChartPanel(xylineChart); frame.add(chartPanel); frame.setVisible(true); try { Thread.sleep(10000); } catch (InterruptedException ex) { System.out.println(ex); } } }
From source file:org.jax.maanova.plot.PlotUtil.java
/** * Create a simple monochrome XY renderer which can be used for scatter plots * @return the renderer//w w w .j a v a2 s . co m */ public static XYLineAndShapeRenderer createMonochromeScatterPlotRenderer() { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesOutlinePaint(false); renderer.setAutoPopulateSeriesOutlineStroke(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBaseShape(new Ellipse2D.Float(-PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS / 2F, -PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS / 2F, PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS, PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS)); renderer.setUseOutlinePaint(true); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setBaseOutlineStroke(new BasicStroke(0.25F)); renderer.clearSeriesPaints(false); renderer.setBasePaint(new Color(0x55, 0x55, 0xFF)); // blue return renderer; }
From source file:com.spotify.heroic.http.render.RenderUtils.java
public static JFreeChart createChart(final List<ShardedResultGroup> groups, final String title, Map<String, String> highlight, Double threshold, int height) { final XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer(true, true); final DeviationRenderer intervalRenderer = new DeviationRenderer(); final XYSeriesCollection regularData = new XYSeriesCollection(); final YIntervalSeriesCollection intervalData = new YIntervalSeriesCollection(); int lineAndShapeCount = 0; int intervalCount = 0; for (final ShardedResultGroup resultGroup : groups) { final MetricCollection group = resultGroup.getMetrics(); if (group.getType() == MetricType.POINT) { final XYSeries series = new XYSeries(resultGroup.getMetrics().toString()); final List<Point> data = group.getDataAs(Point.class); for (final Point d : data) { series.add(d.getTimestamp(), d.getValue()); }/* ww w . j a v a 2 s . c o m*/ lineAndShapeRenderer.setSeriesPaint(lineAndShapeCount, Color.BLUE); lineAndShapeRenderer.setSeriesShapesVisible(lineAndShapeCount, false); lineAndShapeRenderer.setSeriesStroke(lineAndShapeCount, new BasicStroke(2.0f)); regularData.addSeries(series); ++lineAndShapeCount; } if (group.getType() == MetricType.SPREAD) { final YIntervalSeries series = new YIntervalSeries(resultGroup.getMetrics().toString()); final List<Spread> data = group.getDataAs(Spread.class); for (final Spread d : data) { series.add(d.getTimestamp(), d.getSum() / d.getCount(), d.getMin(), d.getMax()); } intervalRenderer.setSeriesPaint(intervalCount, Color.GREEN); intervalRenderer.setSeriesStroke(intervalCount, new BasicStroke(2.0f)); intervalRenderer.setSeriesFillPaint(intervalCount, new Color(200, 255, 200)); intervalRenderer.setSeriesShapesVisible(intervalCount, false); intervalData.addSeries(series); ++intervalCount; } } final JFreeChart chart = buildChart(title, regularData, intervalData, lineAndShapeRenderer, intervalRenderer); chart.setAntiAlias(true); chart.setBackgroundPaint(Color.WHITE); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); if (threshold != null) { final ValueMarker marker = new ValueMarker(threshold, Color.RED, new BasicStroke(Math.max(Math.min(height / 20, 6), 1)), Color.RED, null, 0.5f); plot.addRangeMarker(marker); } plot.setRenderer(lineAndShapeRenderer); // final DateAxis rangeAxis = (DateAxis) plot.getRangeAxis(); // rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); return chart; }
From source file:com.bdb.weather.display.current.WindDirPointer.java
/** * Draws the pointer./* w ww . j av a 2s .c o m*/ * * @param g2 The graphics target. * @param plot The plot. * @param frame The dial's reference frame. * @param view The dial's view. */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setPaint(Color.blue); g2.setStroke(new BasicStroke(1.0f)); DialScale scale = plot.getScaleForDataset(getDatasetIndex()); double value = plot.getValue(getDatasetIndex()); double angle = scale.valueToAngle(value % 360.0); Rectangle2D outerRect = DialPlot.rectangleByRadius(frame, outerRadius, outerRadius); Rectangle2D innerRect = DialPlot.rectangleByRadius(frame, outerRadius - innerOffset, outerRadius - innerOffset); g2.setPaint(getOutlinePaint()); Arc2D arc1 = new Arc2D.Double(outerRect, angle - (ARC_LENGTH / 2), ARC_LENGTH, Arc2D.OPEN); g2.draw(arc1); Arc2D arc2 = new Arc2D.Double(innerRect, angle, 0.0, Arc2D.OPEN); GeneralPath gp = new GeneralPath(); gp.moveTo(arc1.getStartPoint().getX(), arc1.getStartPoint().getY()); gp.lineTo(arc2.getStartPoint().getX(), arc2.getStartPoint().getY()); gp.lineTo(arc1.getEndPoint().getX(), arc1.getEndPoint().getY()); g2.draw(gp); if (fill) { g2.setPaint(getFillPaint()); g2.fill(gp); } }
From source file:it.eng.spagobi.engines.kpi.bo.charttypes.dialcharts.Meter.java
/** * Creates the MeterChart ./* w ww . j ava 2 s . co m*/ * * @return A MeterChart . */ public JFreeChart createChart() { logger.debug("IN"); if (dataset == null) { logger.debug("The dataset to be represented is null"); return null; } MeterPlot plot = new MeterPlot((ValueDataset) dataset); logger.debug("Created new plot"); plot.setRange(new Range(lower, upper)); logger.debug("Setted plot range"); for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); plot.addInterval(new MeterInterval(interval.getLabel(), new Range(interval.getMin(), interval.getMax()), Color.lightGray, new BasicStroke(2.0f), interval.getColor())); logger.debug("Added new interval to the plot"); } plot.setNeedlePaint(Color.darkGray); plot.setDialBackgroundPaint(Color.white); plot.setDialOutlinePaint(Color.gray); plot.setDialShape(DialShape.CHORD); plot.setMeterAngle(260); plot.setTickLabelsVisible(true); Font f = new Font("Arial", Font.PLAIN, 11); plot.setTickLabelFont(f); plot.setTickLabelPaint(Color.darkGray); plot.setTickSize(5.0); plot.setTickPaint(Color.lightGray); plot.setValuePaint(Color.black); plot.setValueFont(new Font("Arial", Font.PLAIN, 14)); logger.debug("Setted all properties of the plot"); JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); logger.debug("Created the chart"); chart.setBackgroundPaint(color); logger.debug("Setted background color of the chart"); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); logger.debug("Setted the title of the chart"); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); logger.debug("Setted the subtitle of the chart"); } logger.debug("OUT"); return chart; }
From source file:net.sf.jasperreports.components.spiderchart.SpiderChartDesignEvaluator.java
/** * //from w ww . ja v a 2 s . co m */ public static JRRenderable evaluateRenderer(ReportConverter reportConverter, JRComponentElement element) { SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent(); ChartSettings chartSettings = chartComponent.getChartSettings(); SpiderPlot plot = chartComponent.getPlot(); SpiderWebPlot spiderWebPlot = new SpiderWebPlot(getSampleDataset()); if (plot.getAxisLineColor() != null) { spiderWebPlot.setAxisLinePaint(plot.getAxisLineColor()); } if (plot.getAxisLineWidth() != null) { spiderWebPlot.setAxisLineStroke(new BasicStroke(plot.getAxisLineWidth())); } if (plot.getBackcolor() != null) { spiderWebPlot.setBackgroundPaint(plot.getBackcolor()); } if (plot.getBackgroundAlpha() != null) { spiderWebPlot.setBackgroundAlpha(plot.getBackgroundAlpha()); } if (plot.getForegroundAlpha() != null) { spiderWebPlot.setForegroundAlpha(plot.getForegroundAlpha()); } if (plot.getHeadPercent() != null) { spiderWebPlot.setHeadPercent(plot.getHeadPercent()); } if (plot.getInteriorGap() != null) { spiderWebPlot.setInteriorGap(plot.getInteriorGap()); } if (plot.getLabelColor() != null) { spiderWebPlot.setLabelPaint(plot.getLabelColor()); } if (plot.getLabelFont() != null) { spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(plot.getLabelFont(), Locale.getDefault())); } if (plot.getLabelGap() != null) { spiderWebPlot.setAxisLabelGap(plot.getLabelGap()); } spiderWebPlot.setMaxValue(MAX_VALUE); if (plot.getRotation() != null) { spiderWebPlot.setDirection(plot.getRotation().getRotation()); } if (plot.getStartAngle() != null) { spiderWebPlot.setStartAngle(plot.getStartAngle()); } if (plot.getTableOrder() != null) { spiderWebPlot.setDataExtractOrder(plot.getTableOrder().getOrder()); } if (plot.getWebFilled() != null) { spiderWebPlot.setWebFilled(plot.getWebFilled()); } spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator()); spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator()); String titleText = JRExpressionUtil.getExpressionText(chartSettings.getTitleExpression()); Font titleFont = chartSettings.getTitleFont() != null ? JRFontUtil.getAwtFont(chartSettings.getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT; JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true); if (chartSettings.getBackcolor() != null) { jfreechart.setBackgroundPaint(chartSettings.getBackcolor()); } RectangleEdge titleEdge = getEdge(chartSettings.getTitlePosition(), RectangleEdge.TOP); if (titleText != null) { TextTitle title = jfreechart.getTitle(); title.setText(titleText); if (chartSettings.getTitleColor() != null) { title.setPaint(chartSettings.getTitleColor()); } title.setFont(titleFont); title.setPosition(titleEdge); jfreechart.setTitle(title); } String subtitleText = JRExpressionUtil.getExpressionText(chartSettings.getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); subtitle.setText(subtitleText); if (chartSettings.getSubtitleColor() != null) { subtitle.setPaint(chartSettings.getSubtitleColor()); } if (chartSettings.getSubtitleColor() != null) { Font subtitleFont = chartSettings.getSubtitleFont() != null ? JRFontUtil.getAwtFont(chartSettings.getSubtitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT; subtitle.setFont(subtitleFont); } subtitle.setPosition(titleEdge); jfreechart.addSubtitle(subtitle); } // Apply all of the legend formatting options LegendTitle legend = jfreechart.getLegend(); if (legend != null) { legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend())); if (legend.isVisible()) { if (chartSettings.getLegendColor() != null) { legend.setItemPaint(chartSettings.getLegendColor()); } if (chartSettings.getLegendBackgroundColor() != null) { legend.setBackgroundPaint(chartSettings.getLegendBackgroundColor()); } if (chartSettings.getLegendFont() != null) { legend.setItemFont(JRFontUtil.getAwtFont(chartSettings.getLegendFont(), Locale.getDefault())); } legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM)); } } Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight()); String renderType = chartSettings.getRenderType(); if (renderType == null) { renderType = JRProperties.getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_RENDER_TYPE); } return ChartUtil.getChartRendererFactory(renderType).getRenderer(jfreechart, null, rectangle); }
From source file:com.haskins.cloudtrailviewer.utils.ChartFactory.java
private static ChartPanel createPieChart(String type, List<Entry<String, Integer>> events, int width, int height) { DefaultPieDataset dataset = new DefaultPieDataset(); for (Map.Entry<String, Integer> event : events) { dataset.setValue(event.getKey(), event.getValue()); }//from w w w .ja va 2s.co m JFreeChart jFChart; if (type.contains("3d")) { jFChart = org.jfree.chart.ChartFactory.createPieChart3D("", dataset, false, true, false); } else { jFChart = org.jfree.chart.ChartFactory.createPieChart("", dataset, false, true, false); } PiePlot plot = (PiePlot) jFChart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.01); plot.setOutlineVisible(false); plot.setLabelGenerator(null); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); TextTitle t = jFChart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setFont(new Font("Arial", Font.BOLD, 16)); final ChartPanel jChartPanel = new ChartPanel(jFChart, width, height, width, height, width, height, false, false, true, true, false, true); jChartPanel.setMinimumDrawWidth(0); jChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); jChartPanel.setMinimumDrawHeight(0); jChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); return jChartPanel; }