List of usage examples for org.jfree.chart.title TextTitle TextTitle
public TextTitle(String text)
From source file:com.swordlord.gozer.components.wicket.graph.GWStackedBarChartPanel.java
public GWStackedBarChartPanel(String id, IModel<?> model, GStackedBarChart child) { super(id, model); gchart = child;/*from ww w . java2s . c o m*/ DataBindingMember dbMemberRowKey = child.getDataBindingMemberRowKey(); DataBindingMember dbMemberTargetId = child.getDataBindingMemberTargetId(); DataBindingMember dbMemberColKey = child.getDataBindingMemberColKey(); DataBindingMember dbMemberValue = child.getDataBindingMemberValue(); DataBindingManager dbManager = child.getDataBindingManager(); DefaultCategoryDataset dcd = new DefaultCategoryDataset(); List<DataRowBase> rows = dbManager.getRows(dbMemberValue); // if the graph has some ordering info in the format of "<field> ASCENDING,<field2> DESCENDING" if (child.hasOrdering()) { List<Ordering> ordering = child.formatOrdering(child.getOrdering()); OrderingEx.orderList(rows, ordering); } for (int j = 0; j < rows.size(); j++) { DataRowBase row = rows.get(j); String strKey = row.getPropertyAsStringForce(dbMemberRowKey.getRelativePathWithField()); dcd.setValue(row.getPropertyAsInt(dbMemberValue.getRelativePathWithField()), strKey, row.getPropertyAsStringForce(dbMemberColKey.getRelativePathWithField())); if (dbMemberTargetId != null) { _target.put(strKey, row.getPropertyAsStringForce(dbMemberTargetId.getDataBindingFieldName())); } } JFreeChart chart = ChartFactory.createStackedBarChart(child.getTitle(), child.getCategoryAxisLabel(), child.getValueAxisLabel(), dcd, child.getOrientation(), child.getLegend(), false, false); // Do this in a more static way! StackedBarRenderer.setDefaultBarPainter(new StandardBarPainter()); //chart.setBackgroundPaint(Color.white); if (child.getSubTitle() != null) { chart.addSubtitle(new TextTitle(child.getSubTitle())); } CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setDrawingSupplier(child.getDrawingSupplier()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(child.getCategoryAxisVisible()); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setVisible(child.getValueAxisVisible()); /* //CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer(); for (int j = 0; j < rowKey.length; j++) { renderer.setSeriesItemLabelGenerator(j, new LabelGenerator(j, rowKey[j])); renderer.setSeriesItemLabelsVisible(j, true); } */ StackedBarRenderer renderer = new StackedBarRenderer(); for (int j = 0; j < dcd.getRowCount(); j++) { renderer.setSeriesItemLabelGenerator(j, new StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelsVisible(j, true); } //renderer.setLegendItemLabelGenerator(new LabelGenerator()); renderer.setShadowVisible(false); plot.setRenderer(renderer); ChartImage image = new ChartImage("chart", chart, child.getWidth(800), child.getHeight(800)); String mapName = child.getCaption(); add(image); DynamicImageMap imageMap = constructImageMap(image, mapName); if (!child.isClickable()) { imageMap.setVisible(false); } else { image.add(new AttributeModifier("usemap", new Model<String>("#" + mapName))); } add(imageMap); }
From source file:org.jfree.chart.demo.SurveyResultsDemo.java
/** * Creates a chart./*from w w w. ja v a2 s. c om*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label dataset, // data PlotOrientation.HORIZONTAL, // orientation false, // include legend true, false); chart.setBackgroundPaint(Color.white); final TextTitle title = new TextTitle("Figure 7 | I. Resources - The site offers users relevant, " + "informative and educational resources"); title.setHorizontalAlignment(HorizontalAlignment.LEFT); title.setBackgroundPaint(Color.red); title.setPaint(Color.white); chart.setTitle(title); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setOutlinePaint(null); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePosition(CategoryAnchor.END); plot.setDomainGridlineStroke(new BasicStroke(0.5f)); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinesVisible(false); plot.clearRangeMarkers(); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setCategoryMargin(0.50); plot.getRangeAxis().setVisible(false); final CategoryItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(0x9C, 0xA4, 0x4A)); renderer.setOutlineStroke(null); renderer.setBaseOutlineStroke(null); renderer.setItemLabelsVisible(true); renderer.setItemLabelFont(new Font("SansSerif", Font.BOLD, 10)); final ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT); renderer.setPositiveItemLabelPosition(position); final CategoryTextAnnotation a1 = new CategoryTextAnnotation("1. White papers are available.", "Category 1", 0.0); a1.setFont(new Font("SansSerif", Font.BOLD, 12)); a1.setTextAnchor(TextAnchor.BOTTOM_LEFT); a1.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a1); final CategoryTextAnnotation a2 = new CategoryTextAnnotation( "2. White papers enhance users " + "understanding of the firm and its expertise.", "Category 2", 0.0); a2.setFont(new Font("SansSerif", Font.PLAIN, 12)); a2.setTextAnchor(TextAnchor.BOTTOM_LEFT); a2.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a2); final CategoryTextAnnotation a3 = new CategoryTextAnnotation( "3. White papers are relevant to " + "the firm's prospects and clients.", "Category 3", 0.0); a3.setFont(new Font("SansSerif", Font.PLAIN, 12)); a3.setTextAnchor(TextAnchor.BOTTOM_LEFT); a3.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a3); final CategoryTextAnnotation a4 = new CategoryTextAnnotation( "4. White papers are relevant to " + "the firm's positioning.", "Category 4", 0.0); a4.setFont(new Font("SansSerif", Font.PLAIN, 12)); a4.setTextAnchor(TextAnchor.BOTTOM_LEFT); a4.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a4); final CategoryTextAnnotation a5 = new CategoryTextAnnotation("5. Case studies are available.", "Category 5", 0.0); a5.setFont(new Font("SansSerif", Font.BOLD, 12)); a5.setTextAnchor(TextAnchor.BOTTOM_LEFT); a5.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a5); final CategoryTextAnnotation a6 = new CategoryTextAnnotation( "6. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 6", 0.0); a6.setFont(new Font("SansSerif", Font.PLAIN, 12)); a6.setTextAnchor(TextAnchor.BOTTOM_LEFT); a6.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a6); final CategoryTextAnnotation a7 = new CategoryTextAnnotation( "7. Case studies are relevant to " + "the firm's prospects and clients.", "Category 7", 0.0); a7.setFont(new Font("SansSerif", Font.PLAIN, 12)); a7.setTextAnchor(TextAnchor.BOTTOM_LEFT); a7.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a7); final CategoryTextAnnotation a8 = new CategoryTextAnnotation( "8. White papers are relevant to the firm's positioning.", "Category 8", 0.0); a8.setFont(new Font("SansSerif", Font.PLAIN, 12)); a8.setTextAnchor(TextAnchor.BOTTOM_LEFT); a8.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a8); final CategoryTextAnnotation a9 = new CategoryTextAnnotation("9. Case studies are available.", "Category 9", 0.0); a9.setFont(new Font("SansSerif", Font.BOLD, 12)); a9.setTextAnchor(TextAnchor.BOTTOM_LEFT); a9.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a9); final CategoryTextAnnotation a10 = new CategoryTextAnnotation( "10. Case studies enhance users " + "understanding of the firm and its expertise.", "Category 10", 0.0); a10.setFont(new Font("SansSerif", Font.PLAIN, 12)); a10.setTextAnchor(TextAnchor.BOTTOM_LEFT); a10.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a10); final CategoryTextAnnotation a11 = new CategoryTextAnnotation( "11. Case studies are relevant " + "to the firm's prospects and clients.", "Category 11", 0.0); a11.setFont(new Font("SansSerif", Font.PLAIN, 12)); a11.setTextAnchor(TextAnchor.BOTTOM_LEFT); a11.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a11); final CategoryTextAnnotation a12 = new CategoryTextAnnotation( "12. White papers are relevant to the firm's positioning.", "Category 12", 0.0); a12.setFont(new Font("SansSerif", Font.PLAIN, 12)); a12.setTextAnchor(TextAnchor.BOTTOM_LEFT); a12.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a12); final CategoryTextAnnotation a13 = new CategoryTextAnnotation( "13. Users can easily access " + "resources based on viewer interest.", "Category 13", 0.0); a13.setFont(new Font("SansSerif", Font.BOLD, 12)); a13.setTextAnchor(TextAnchor.BOTTOM_LEFT); a13.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a13); final CategoryTextAnnotation a14 = new CategoryTextAnnotation( "14. Access to additional hyperlinks enhances users's ability to find relevant " + "information.", "Category 14", 0.0); a14.setFont(new Font("SansSerif", Font.BOLD, 12)); a14.setTextAnchor(TextAnchor.BOTTOM_LEFT); a14.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a14); final CategoryTextAnnotation a15 = new CategoryTextAnnotation("15. OVERALL EFFECTIVENESS.", "Overall", 0.0); a15.setFont(new Font("SansSerif", Font.BOLD, 12)); a15.setTextAnchor(TextAnchor.BOTTOM_LEFT); a15.setCategoryAnchor(CategoryAnchor.START); plot.addAnnotation(a15); return chart; }
From source file:org.schreibubi.JCombinations.logic.visitors.ChartNodesVisitor.java
public void visit(Shmoo s) throws Exception { if (s.componentSelected(this.treePaths, OurTreeNode.MYSELF | OurTreeNode.PARENTS | OurTreeNode.CHILDS)) { NumberAxis xAxis = new NumberAxis(s.getTrim() + " [" + s.getXdataDefault().getUnit() + "]"); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis( s.getMeasure() + " [" + ((Ydata) s.getYdata().get(0)).getUnit() + "]"); yAxis.setAutoRangeIncludesZero(false); XYLineAndShapeRenderer renderer = new XYLineAndShapeRendererExtended(true, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); this.dutData = new ArrayList<ArrayList<Double>>(); this.dutName = new ArrayList<String>(); for (int i = 0; i < s.getChildCount(); i++) (s.getChildAt(i)).accept(this); XYSeriesCollection xyseries = new XYSeriesCollection(); ArrayList<Double> x = s.getXdataDefault().getXPositions(); for (int j = 0; j < this.dutData.size(); j++) { ArrayList<Double> y = this.dutData.get(j); XYSeries xy = new XYSeries(this.dutName.get(j)); for (int i = 0; i < y.size(); i++) xy.add(x.get(i), y.get(i)); xyseries.addSeries(xy);/*from ww w. ja v a 2 s. co m*/ } XYPlot plot = new XYPlot(xyseries, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); Marker marker = s.getMarker(); if (marker != null) plot.addRangeMarker(marker, Layer.BACKGROUND); ExtendedJFreeChart chart = new ExtendedJFreeChart(s.getDescription(), JFreeChart.DEFAULT_TITLE_FONT, plot, false); if (marker == null) chart.addSubtitle(new TextTitle(s.getSubtitle())); else chart.addSubtitle(new TextTitle( s.getSubtitle() + " " + s.getValueAt(3) + "/" + s.getValueAt(4) + "/" + s.getValueAt(5))); chart.setTreePath(s.getTreePath()); this.charts.add(chart); } }
From source file:eu.delving.stats.ChartHelper.java
private static JFreeChart createFieldFrequencyChart(Stats.RecordStats recordStats, Path path, String name) { Stats.Histogram histogram = recordStats.frequencies.get(path); if (histogram == null) return null; List<Stats.Counter> sorted = sort(histogram.counterMap.values(), MAX_BAR_CHART_SIZE, recordStats.recordCount);/*from w w w .j a va 2 s . co m*/ DefaultCategoryDataset data = new DefaultCategoryDataset(); data.addValue(histogram.absent, "Frequency", "0"); for (Stats.Counter counter : sorted) data.addValue(counter.count, "Frequency", counter.value); JFreeChart chart = ChartFactory.createBarChart(String.format("Frequency within record in %s", name), "Occurrences", "Frequency", data, PlotOrientation.VERTICAL, false, true, false); chart.addSubtitle(new TextTitle(path.toString())); return finishBarChart(chart, new Color(30, 144, 225)); }
From source file:net.sf.jasperreports.components.spiderchart.SpiderChartDesignEvaluator.java
/** * //w w w.j a va 2 s. com */ 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:unalcol.termites.boxplots.InformationCollected1.java
/** * Creates a new demo.//from w ww . jav a2s . com * * @param title the frame title. * @param pf */ public InformationCollected1(final String title, ArrayList<Double> pf) { super(title); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf); final CategoryAxis xAxis = new CategoryAxis(""); final NumberAxis yAxis = new NumberAxis(""); //final NumberAxis yAxis = new NumberAxis("Information Collected"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 14); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Information Collected " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setFont(font); legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); chart.getLegend().setItemFont(font); FileOutputStream output; try { output = new FileOutputStream("informationcollected1" + mazeMode + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 450, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(InformationCollected1.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InformationCollected1.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.itemanalysis.jmetrik.graph.barchart.BarChartPanel.java
public void setGraph() throws IllegalArgumentException { boolean hasGroupingVariable = false; if (command.getFreeOption("groupvar").hasValue()) { hasGroupingVariable = true;/*from w w w . jav a2 s . c om*/ } String name = command.getFreeOption("variable").getString(); String xLabel = name; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String yLabel = ""; if (command.getSelectOneOption("yaxis").isValueSelected("freq")) { yLabel = "Frequency"; } else { yLabel = "Percentage"; } if (command.getSelectOneOption("layout").isValueSelected("stacked")) { chart = ChartFactory.createStackedBarChart(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } else if (command.getSelectOneOption("view").isValueSelected("3D")) { chart = ChartFactory.createBarChart3D(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); } else { chart = ChartFactory.createBarChart(command.getFreeOption("title").getString(), xLabel, yLabel, dataset, chartOrientation, hasGroupingVariable, //only show legend if has grouping variable true, false); } String sub = ""; if (command.getFreeOption("subtitle").getString() != null) { sub = command.getFreeOption("subtitle").getString(); } TextTitle subtitle1 = new TextTitle(sub); chart.addSubtitle(subtitle1); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); if (command.getSelectOneOption("layout").isValueSelected("layered")) { LayeredBarRenderer renderer = new LayeredBarRenderer(); // renderer.setDrawBarOutline(false); plot.setRenderer(renderer); plot.setRowRenderingOrder(SortOrder.DESCENDING); } chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(BarChartPanel.this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); // plot.setForegroundAlpha(0.80f); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); this.setBackground(Color.WHITE); this.add(panel); }
From source file:com.seniorproject.augmentedreality.test.AreaChartDemo.java
/** * Creates a chart.// ww w . j av a 2 s . c o m * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setAnchor(StandardLegend.SOUTH); chart.setBackgroundPaint(Color.white); final TextTitle subtitle = new TextTitle("An area chart demonstration. We use this " + "subtitle as an example of what happens when you get a really long title or " + "subtitle."); subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12)); subtitle.setPosition(RectangleEdge.TOP); // subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05)); subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM); chart.addSubtitle(subtitle); final CategoryPlot plot = chart.getCategoryPlot(); plot.setForegroundAlpha(0.5f); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:v800_trainer.XYGraphik.java
public JPanel StartGraphik(JCicloTronic JTronicHandle) { int num = 0;/*from w w w . j a v a 2 s . c om*/ int num2 = 0, num0, num02; //fr Streckendifferenz int selected; int single; int i; int j; int Stunden; int Minuten; int Sekunden; int Tagadder = 0; int Linecount = 0; Second xTime[]; double xWerte[]; double xWerte2[];//fr Streckendifferenz double y1Werte[]; double y2Werte[]; double y3Werte[]; double y4Werte[]; double y5Werte[]; double y6Werte[]; double y7Werte[]; double y8Werte[]; double y8bWerte[]; double y9Werte[]; double y10Werte[]; JFreeChart chart; Rectangle2D.Double Legendenpunkt = new Rectangle2D.Double(); selected = JTronicHandle.Auswahl_Graphik.getSelectedIndex(); if (selected == 0) { single = 1; } else { single = 0; } //Defaultchart erstellen if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) { XYSeries dataset = new XYSeries(""); dataset.add(1, 1); XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); chart = ChartFactory.createXYLineChart("Multiple Axis Demo 1", "Strecke", "", dataset1, PlotOrientation.HORIZONTAL, true, true, false); } else { TimeSeries dataset = new TimeSeries(""); dataset.add(new Second(1, 1, 1, 1, 1, 1900), 1); TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Zeit", "", dataset1, true, true, false); } ; //Tooltips fr Zeitachse einstellen // XYToolTipGenerator ToolTip = new StandardXYToolTipGenerator("{0}: ({1}, {2})", // (DateFormat) new SimpleDateFormat("kk:mm.ss"), // NumberFormat.getInstance()); // chart.setAntiAlias(true); chart.setNotify(false); if (single == 0) { chart.setTitle(JTronicHandle.Statistikhandle.TourData[JTronicHandle.Auswahl_Graphik .getSelectedIndex()].DataProperty.getProperty("Titel", "")); chart.addSubtitle(new TextTitle(JTronicHandle.Auswahl_Graphik.getItemAt(selected).toString())); } else { chart.setTitle("Mehrfache Daten"); } chart.setBackgroundPaint(Color.white); JTronicHandle.applyChartTheme(chart); XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); 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); plot.setRangeCrosshairLockedOnData(false); plot.setDomainCrosshairLockedOnData(false); int Anzahl_Kurven = Integer.parseInt(JTronicHandle.Properties.getProperty("AnzahlKurven", "5")) + 1; if (Anzahl_Kurven > JTronicHandle.Auswahl_Graphik.getItemCount()) { Anzahl_Kurven = JTronicHandle.Auswahl_Graphik.getItemCount(); } try { for (j = 0; j < (Anzahl_Kurven - 2) * single + 1; j++) { if (single == 1) { selected = j + 1; } num = JTronicHandle.Statistikhandle.TourData[selected].Datenpunkte; num2 = JTronicHandle.Statistikhandle.TourData[selected].ZahlStreckenPunkte; num0 = JTronicHandle.Statistikhandle.TourData[1].ZahlStreckenPunkte; num02 = JTronicHandle.Statistikhandle.TourData[1].Datenpunkte; xTime = new Second[num]; xWerte = new double[num]; y1Werte = new double[num]; y2Werte = new double[num]; y3Werte = new double[num]; y4Werte = new double[num]; y5Werte = new double[num]; y6Werte = new double[num]; y7Werte = new double[num]; y8Werte = new double[num]; y8bWerte = new double[num]; xWerte2 = new double[num2]; y9Werte = new double[num2]; y10Werte = new double[num]; for (i = 0; i < num; i++) { xWerte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Strecke_gesZeit[i]; y1Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Geschw_gesZeit[i]; y2Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Hoehe_gesZeit[i]; y3Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Hf_gesZeit[i]; y4Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Temperatur_gesZeit[i]; y5Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Steigp_gesZeit[i]; y6Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Steigm_gesZeit[i]; y7Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].av_Geschw_gesZeit[i]; y8Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Cadence_gesZeit[i]; y8bWerte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Schritt_lnge[i]; } if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) { int p = 0; if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) { for (i = 0; i < num2; i++) { xWerte2[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].Streckenskala[i]; if (i < num0) { y9Werte[i] = (double) JTronicHandle.Statistikhandle.TourData[selected].ZeitberStrecke[i] - JTronicHandle.Statistikhandle.TourData[1].ZeitberStrecke[i]; } else { y9Werte[i] = y9Werte[i - 1]; } } } else { for (i = 0; i < num; i++) { p = 0; while (p < num02 - 1 && (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] >= JTronicHandle.Statistikhandle.TourData[1].gesZeit[p])) { p++; } ; if (i < num02) { y10Werte[i] = (double) (JTronicHandle.Statistikhandle.TourData[selected].Strecke_gesZeit[i] - JTronicHandle.Statistikhandle.TourData[1].Strecke_gesZeit[p]) * 100.0; } else { y10Werte[i] = y10Werte[i - 1]; } } } } //Zeitbasis laden for (i = 0; i < num; i++) { Tagadder = 0; Stunden = (int) (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] / 3600); Minuten = (int) ((JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] - Stunden * 3600) / 60); Sekunden = (int) (JTronicHandle.Statistikhandle.TourData[selected].gesZeit[i] - Stunden * 3600 - Minuten * 60); if (single == 0) { Minuten = Minuten + JTronicHandle.Statistikhandle.TourData[selected].StartMinuten; if (Minuten >= 60) { Minuten -= 60; Stunden++; } ; Stunden = Stunden + JTronicHandle.Statistikhandle.TourData[selected].StartStunden; } ; while (Stunden >= 24) { Stunden -= 24; Tagadder += 1; } ; try { if (single == 0) { xTime[i] = new Second(Sekunden, Minuten, Stunden, JTronicHandle.Statistikhandle.TourData[selected].Tag + Tagadder, JTronicHandle.Statistikhandle.TourData[selected].Monat, JTronicHandle.Statistikhandle.TourData[selected].Jahr); } else { xTime[i] = new Second(Sekunden, Minuten, Stunden, 1 + Tagadder, 1, 1900); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "StartGraphik\n" + e + "Zeile " + i + " Zeitfehler " + Stunden + " " + Minuten + " " + Sekunden, "Achtung!", JOptionPane.ERROR_MESSAGE); } } if (JTronicHandle.Graphik_Radio_Strecke.isSelected()) { //Streckenachse if (JTronicHandle.Graphik_check_Geschwindigkeit.isSelected()) { XYSeries dataset = new XYSeries( "Geschwindigkeit [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y1Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Hhe.isSelected()) { XYSeries dataset = new XYSeries( "Hhe [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y2Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); NumberAxis axis2 = new NumberAxis("Hhe [m]"); axis2.setLabelFont(plot.getRangeAxis().getLabelFont()); axis2.setTickLabelFont(plot.getRangeAxis().getTickLabelFont()); axis2.setAutoRangeIncludesZero(true); axis2.setLabelPaint(Color.BLACK); axis2.setTickLabelPaint(Color.BLACK); axis2.setAxisLinePaint(Color.BLACK); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 1); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } ; if (JTronicHandle.Graphik_check_HF.isSelected()) { XYSeries dataset = new XYSeries( "Herzfrequenz [b/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y3Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Temp.isSelected()) { XYSeries dataset = new XYSeries( "Temperatur [C] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y4Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_p.isSelected()) { XYSeries dataset = new XYSeries( "Steigung [%] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y5Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_m.isSelected()) { XYSeries dataset = new XYSeries( "Steigung [m/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y6Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_av_Geschw.isSelected()) { XYSeries dataset = new XYSeries( "av Geschw. [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y7Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Cadence.isSelected()) { XYSeries dataset = new XYSeries( "Cadence [n/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y8Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Schrittlnge.isSelected()) { XYSeries dataset = new XYSeries( "Schrittlnge [cm] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xWerte[i], y8bWerte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) { XYSeries dataset = new XYSeries( "Zeitabstand [s] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr + " - " + JTronicHandle.Statistikhandle.TourData[1].Tag + "." + JTronicHandle.Statistikhandle.TourData[1].Monat + "." + JTronicHandle.Statistikhandle.TourData[1].Jahr); for (i = 0; i < num2; i++) { dataset.add(xWerte2[i], y9Werte[i]); } XYSeriesCollection dataset1 = new XYSeriesCollection(dataset); NumberAxis axis3 = new NumberAxis("Abstand"); axis3.setLabelFont(plot.getRangeAxis().getLabelFont()); axis3.setTickLabelFont(plot.getRangeAxis().getTickLabelFont()); axis3.setAutoRangeIncludesZero(true); axis3.setLabelPaint(Color.BLACK); axis3.setTickLabelPaint(Color.BLACK); plot.setRangeAxis(2, axis3); plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 2); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } } else { //Zeitachse if (JTronicHandle.Graphik_check_Geschwindigkeit.isSelected()) { TimeSeries dataset = new TimeSeries( "Geschwindigkeit [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y1Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); ValueAxis axis = plot.getRangeAxis(); axis.setLabelPaint(Color.BLACK); axis.setTickLabelPaint(Color.BLACK); plot.setRangeAxis(0, axis); plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Hhe.isSelected()) { TimeSeries dataset = new TimeSeries( "Hoehe [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y2Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); NumberAxis axis2 = (NumberAxis) plot.getRangeAxis().clone(); axis2.setLabel("Hhe [m]"); axis2.setAutoRangeIncludesZero(true); axis2.setLabelPaint(Color.BLACK); axis2.setTickLabelPaint(Color.BLACK); axis2.setAxisLinePaint(Color.BLACK); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 1); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_HF.isSelected()) { TimeSeries dataset = new TimeSeries( "Herzfrequenz [b/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y3Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Temp.isSelected()) { TimeSeries dataset = new TimeSeries( "Temperatur [C] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y4Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_p.isSelected()) { TimeSeries dataset = new TimeSeries("Steigung [%] "); for (i = 0; i < num; i++) { dataset.add(xTime[i], y5Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Steigung_m.isSelected()) { TimeSeries dataset = new TimeSeries( "Steigung [m/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y6Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_av_Geschw.isSelected()) { TimeSeries dataset = new TimeSeries( "av Geschw. [km/h] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y7Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Cadence.isSelected()) { TimeSeries dataset = new TimeSeries( "Cadence [n/min] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y8Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Schrittlnge.isSelected()) { TimeSeries dataset = new TimeSeries( "Schrittlnge [cm] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y8bWerte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 0); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } if (JTronicHandle.Graphik_check_Abstand.isSelected() && single == 1 && j != 0) { TimeSeries dataset = new TimeSeries( "Streckenabstand [m] " + JTronicHandle.Statistikhandle.TourData[selected].Tag + "." + JTronicHandle.Statistikhandle.TourData[selected].Monat + "." + JTronicHandle.Statistikhandle.TourData[selected].Jahr + " - " + JTronicHandle.Statistikhandle.TourData[1].Tag + "." + JTronicHandle.Statistikhandle.TourData[1].Monat + "." + JTronicHandle.Statistikhandle.TourData[1].Jahr); for (i = 0; i < num; i++) { dataset.add(xTime[i], y10Werte[i]); } TimeSeriesCollection dataset1 = new TimeSeriesCollection(dataset); ValueAxis axis3 = (ValueAxis) plot.getRangeAxis().clone(); axis3.setLabel("Abstand"); axis3.setLabelPaint(Color.BLACK); axis3.setTickLabelPaint(Color.BLACK); plot.setRangeAxis(2, axis3); plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(Linecount, dataset1); plot.mapDatasetToRangeAxis(Linecount, 2); XYItemRenderer renderer = new StandardXYItemRenderer(2);//, ToolTip); renderer.setSeriesPaint(0, getColour(Linecount)); // renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(Linecount, renderer); Linecount++; } } } chart.setNotify(true); ChartPanel Panel = new ChartPanel(chart); return Panel; } catch (Exception e) { JOptionPane.showMessageDialog(null, "StartGraphik\nSchluss_Fehler: " + e, "Achtung!", JOptionPane.ERROR_MESSAGE); } return new ChartPanel(chart); }
From source file:net.sf.jasperreports.components.spiderchart.SpiderChartRendererEvaluator.java
/** * /* w w w .j a v a 2s . c o m*/ */ public static Renderable evaluateRenderable(JasperReportsContext jasperReportsContext, JRComponentElement element, SpiderChartSharedBean spiderchartBean, ChartCustomizer chartCustomizer, String defaultRenderType, String datasetType) { SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent(); ChartSettings chartSettings = chartComponent.getChartSettings(); SpiderPlot plot = (SpiderPlot) chartComponent.getPlot(); DefaultCategoryDataset dataset = null; StandardCategoryItemLabelGenerator labelGenerator = null; if (FILL_DATASET.equals(datasetType)) { dataset = ((FillSpiderDataset) spiderchartBean.getDataset()).getCustomDataset(); labelGenerator = ((FillSpiderDataset) spiderchartBean.getDataset()).getLabelGenerator(); } else { dataset = getSampleDataset(); labelGenerator = new StandardCategoryItemLabelGenerator(); } SpiderWebPlot spiderWebPlot = new SpiderWebPlot(dataset); 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(FontUtil.getInstance(jasperReportsContext).getAwtFont(plot.getLabelFont(), Locale.getDefault())); } if (plot.getLabelGap() != null) { spiderWebPlot.setAxisLabelGap(plot.getLabelGap()); } if (spiderchartBean.getMaxValue() != null) { spiderWebPlot.setMaxValue(spiderchartBean.getMaxValue()); } 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(labelGenerator); Font titleFont = chartSettings.getTitleFont() != null ? FontUtil.getInstance(jasperReportsContext) .getAwtFont(chartSettings.getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT; String titleText = spiderchartBean.getTitleText(); JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true); Color backcolor = chartSettings.getBackcolor() != null ? chartSettings.getBackcolor() : element.getBackcolor(); if (backcolor != null) { jfreechart.setBackgroundPaint(backcolor); } 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 = spiderchartBean.getSubtitleText(); 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 ? FontUtil.getInstance(jasperReportsContext).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(FontUtil.getInstance(jasperReportsContext) .getAwtFont(chartSettings.getLegendFont(), Locale.getDefault())); } legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM)); } } String renderType = chartSettings.getRenderType() == null ? defaultRenderType : chartSettings.getRenderType(); Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight()); if (chartCustomizer != null) { chartCustomizer.customize(jfreechart, chartComponent); } return ChartUtil.getInstance(jasperReportsContext).getChartRenderableFactory(renderType) .getRenderable(jasperReportsContext, jfreechart, spiderchartBean.getHyperlinkProvider(), rectangle); }