use of org.jfree.chart.renderer.xy.XYDotRenderer in project pentaho-platform by pentaho.
the class JFreeChartEngine method createXYSeriesCollectionChart.
private static JFreeChart createXYSeriesCollectionChart(final XYSeriesCollectionChartDefinition chartDefinition) {
JFreeChart chart = null;
// TODO Make the following accessible from the chartDefinition
String domainAxisLabel = null;
String rangeAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
NumberAxis domainAxis = chartDefinition.isThreeD() ? new NumberAxis3D(domainAxisLabel) : new NumberAxis(domainAxisLabel);
domainAxis.setAutoRangeIncludesZero(chartDefinition.isDomainIncludesZero());
domainAxis.setAutoRangeStickyZero(chartDefinition.isDomainStickyZero());
ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
AbstractXYItemRenderer renderer = null;
switch(chartDefinition.getChartType()) {
case LINE_CHART_TYPE:
renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible());
((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible());
break;
case AREA_CHART_TYPE:
renderer = new XYAreaRenderer();
break;
case STEP_CHART_TYPE:
renderer = new XYStepRenderer();
break;
case STEP_AREA_CHART_TYPE:
renderer = new XYStepAreaRenderer();
break;
case DIFFERENCE_CHART_TYPE:
renderer = new XYDifferenceRenderer();
break;
case DOT_CHART_TYPE:
renderer = new XYDotRenderer();
((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight());
((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth());
break;
default:
// should log an error if invalid chart type passed in - at least return null for no renderer
return null;
}
if (renderer != null && legend) {
renderer.setLegendItemURLGenerator(new StandardXYSeriesLabelGenerator());
}
if (tooltips) {
XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new DecimalFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat()));
renderer.setToolTipGenerator(generator);
}
if (urls) {
renderer.setURLGenerator(new StandardXYURLGenerator());
}
renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
JFreeChartEngine.updatePlot(plot, chartDefinition);
chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
use of org.jfree.chart.renderer.xy.XYDotRenderer in project Course_Generator by patrovite.
the class JPanelAnalysisSpeedSlope method CreateChart.
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
JFreeChart chart = ChartFactory.createScatterPlot("", // "Slope",
bundle.getString("JPanelAnalysisSpeedSlope.labelX"), // "Speed",
bundle.getString("JPanelAnalysisSpeedSlope.labelY"), // include legend
dataset1, // include legend
PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
// Panel background color
chart.setBackgroundPaint(Color.white);
chart.setAntiAlias(true);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.gray);
plot.setRangeGridlinePaint(Color.gray);
plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
XYDotRenderer renderer = new XYDotRenderer();
renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
renderer.setDotWidth(4);
renderer.setDotHeight(4);
// renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
// renderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
plot.setRenderer(renderer);
NumberAxis rangeAxis2 = new NumberAxis();
plot.setRangeAxis(1, rangeAxis2);
plot.setDataset(1, dataset2);
plot.setRangeAxis(1, rangeAxis2);
plot.mapDatasetToRangeAxis(1, 1);
StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
renderer2.setSeriesPaint(0, Color.red);
plot.setRenderer(1, renderer2);
// -- Select the display order
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
return chart;
}
use of org.jfree.chart.renderer.xy.XYDotRenderer in project mafscaling by vimsh.
the class AMafScaling method createChart.
protected void createChart(JPanel plotPanel, String y2AxisName) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
mafChartPanel = new MafChartPanel(chart, this);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.CENTER;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.insets = insets3;
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 1;
plotPanel.add(mafChartPanel.getChartPanel(), gbl_chartPanel);
XYDotRenderer dotRenderer = new XYDotRenderer();
dotRenderer.setSeriesPaint(0, new Color(0, 51, 102));
dotRenderer.setDotHeight(3);
dotRenderer.setDotWidth(3);
XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesStroke(1, stroke);
lineRenderer.setSeriesStroke(2, stroke);
lineRenderer.setSeriesPaint(0, new Color(34, 139, 34));
lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
lineRenderer.setSeriesPaint(2, new Color(201, 0, 0));
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setSeriesShape(1, ShapeUtilities.createUpTriangle((float) 2.5));
lineRenderer.setSeriesShape(2, ShapeUtilities.createDownTriangle((float) 2.5));
mafChartPanel.enablePointsDrag(0);
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = 7593430826693873496L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
ValueAxis mafvDomain = new NumberAxis(XAxisName);
ValueAxis mafgsRange = new NumberAxis(Y1AxisName);
ValueAxis afrerrRange = new NumberAxis(y2AxisName);
XYSeriesCollection scatterDataset = new XYSeriesCollection(runData);
XYSeriesCollection lineDataset = new XYSeriesCollection();
currMafData.setDescription(currentDataName);
corrMafData.setDescription(correctedDataName);
smoothMafData.setDescription(smoothedDataName);
lineDataset.addSeries(smoothMafData);
lineDataset.addSeries(corrMafData);
lineDataset.addSeries(currMafData);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, mafvDomain);
plot.setRangeAxis(0, mafgsRange);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
plot.setDataset(1, scatterDataset);
plot.setRenderer(1, dotRenderer);
plot.setRangeAxis(1, afrerrRange);
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
Aggregations