use of org.jfree.chart.labels.XYToolTipGenerator 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.labels.XYToolTipGenerator in project pentaho-platform by pentaho.
the class JFreeChartEngine method createStackedTimeSeriesChart.
/*
* The only type of chart this method will produce is a stacked XY area chart with a time series dimension. This
* is because the dataset that jFreeChart expects is different than the regular TimeSeriesCOllection. More
* lipstick on this homely pig.
*/
private static JFreeChart createStackedTimeSeriesChart(final TimeTableXYDatasetChartDefinition 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();
DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault());
ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
XYItemRenderer renderer = null;
switch(chartDefinition.getChartType()) {
case AREA_CHART_TYPE:
renderer = chartDefinition.isStacked() ? new StackedXYAreaRenderer2() : new XYAreaRenderer();
break;
default:
// should log an error if invalid chart type passed in - at least return null for no renderer
return null;
}
if (tooltips) {
XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(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.labels.XYToolTipGenerator in project pentaho-platform by pentaho.
the class BubbleRenderer method drawItem.
/**
* Draws the visual representation of a single data item.
*
* @param g2
* the graphics device.
* @param state
* the renderer state.
* @param dataArea
* the area within which the data is being drawn.
* @param info
* collects information about the drawing.
* @param plot
* the plot (can be used to obtain standard color information etc).
* @param domainAxis
* the domain (horizontal) axis.
* @param rangeAxis
* the range (vertical) axis.
* @param dataset
* the dataset (an {@link XYZDataset} is expected).
* @param series
* the series index (zero-based).
* @param item
* the item index (zero-based).
* @param crosshairState
* crosshair information for the plot (<code>null</code> permitted).
* @param pass
* the pass index.
*/
@Override
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) {
PlotOrientation orientation = plot.getOrientation();
// get the data point...
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double z = Double.NaN;
if (dataset instanceof XYZDataset) {
XYZDataset xyzData = (XYZDataset) dataset;
z = xyzData.getZValue(series, item);
}
if (!Double.isNaN(z)) {
RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);
double circleSize;
circleSize = maxSize * (z / maxZ);
circleSize = Math.abs(circleSize);
Ellipse2D circle = null;
if (orientation == PlotOrientation.VERTICAL) {
circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize);
} else if (orientation == PlotOrientation.HORIZONTAL) {
circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize);
}
g2.setPaint(getItemPaint(series, item));
g2.fill(circle);
g2.setStroke(getItemOutlineStroke(series, item));
g2.setPaint(getItemOutlinePaint(series, item));
g2.draw(circle);
if (isItemLabelVisible(series, item)) {
if (orientation == PlotOrientation.VERTICAL) {
drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
} else if (orientation == PlotOrientation.HORIZONTAL) {
drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
}
}
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
// add an entity for the item...
if (entities != null) {
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series, item);
}
XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url);
entities.add(entity);
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);
}
}
Aggregations