use of org.jfree.chart.labels.XYToolTipGenerator in project processdash by dtuma.
the class XYChart method createChart.
/** Create a scatter plot. */
@Override
public JFreeChart createChart() {
JFreeChart chart;
String xLabel = null, yLabel = null;
if (!chromeless) {
xLabel = Translator.translate(data.getColName(1));
yLabel = getSetting("yLabel");
if (yLabel == null && data.numCols() == 2)
yLabel = data.getColName(2);
if (yLabel == null)
yLabel = getSetting("units");
if (yLabel == null)
yLabel = "Value";
yLabel = Translator.translate(yLabel);
}
Object autoZero = parameters.get("autoZero");
boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0 && data.getData(1, 1) instanceof DateData;
if (firstColumnContainsDate || parameters.get("xDate") != null) {
chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true, false);
if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly())
chart.getXYPlot().getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance()));
} else {
XYDataset src = data.xyDataSource();
chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true, false);
if (src instanceof XYToolTipGenerator) {
chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src);
}
String trendLine = getParameter("trend");
if ("none".equalsIgnoreCase(trendLine))
;
else if ("average".equalsIgnoreCase(trendLine))
addTrendLine(chart, XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y")));
else
addTrendLine(chart, XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y")));
}
if (autoZero != null) {
if (!"x".equals(autoZero))
((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true);
if (!"y".equals(autoZero))
((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true);
}
if (data.numCols() == 2)
chart.removeLegend();
return chart;
}
use of org.jfree.chart.labels.XYToolTipGenerator in project pentaho-platform by pentaho.
the class JFreeChartEngine method createTimeSeriesCollectionChart.
private static JFreeChart createTimeSeriesCollectionChart(final TimeSeriesCollectionChartDefinition 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 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 (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 lotro-companion by dmorcellet.
the class CharacterLevelChartController method buildChart.
private JFreeChart buildChart() {
String title = "Characters levelling";
String timeAxisLabel = "Time";
String valueAxisLabel = "Level";
XYDataset xydataset = createDataset();
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, timeAxisLabel, valueAxisLabel, xydataset, true, true, false);
Color foregroundColor = GuiFactory.getForegroundColor();
Paint backgroundPaint = GuiFactory.getBackgroundPaint();
jfreechart.setBackgroundPaint(backgroundPaint);
TextTitle t = new TextTitle(title);
t.setFont(t.getFont().deriveFont(24.0f));
t.setPaint(foregroundColor);
jfreechart.setTitle(t);
XYPlot plot = jfreechart.getXYPlot();
plot.setDomainPannable(false);
XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {
@Override
public String generateLabelString(XYDataset dataset, int series, int item) {
String name = (String) ((XYSeriesCollection) dataset).getSeriesKey(series);
int level = (int) dataset.getYValue(series, item);
double timestamp = dataset.getXValue(series, item);
String date = Formats.getDateString(Long.valueOf((long) timestamp));
return name + " - " + level + " (" + date + ")";
}
};
XYItemRenderer renderer = plot.getRenderer();
renderer.setBaseToolTipGenerator(tooltip);
// Time axis
DateAxis axis = (DateAxis) plot.getDomainAxis();
SimpleDateFormat sdf = Formats.getDateFormatter();
axis.setDateFormatOverride(sdf);
axis.setAxisLinePaint(foregroundColor);
axis.setLabelPaint(foregroundColor);
axis.setTickLabelPaint(foregroundColor);
// Level axis
NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
valueAxis.setAutoRange(true);
valueAxis.setAxisLinePaint(foregroundColor);
valueAxis.setLabelPaint(foregroundColor);
valueAxis.setTickLabelPaint(foregroundColor);
TickUnitSource ticks = getLevelTicks();
valueAxis.setStandardTickUnits(ticks);
LegendTitle legend = jfreechart.getLegend();
legend.setPosition(RectangleEdge.BOTTOM);
legend.setItemPaint(foregroundColor);
legend.setBackgroundPaint(backgroundPaint);
return jfreechart;
}
use of org.jfree.chart.labels.XYToolTipGenerator in project lotro-companion by dmorcellet.
the class CraftingHistoryChartController method buildChart.
private JFreeChart buildChart() {
String title = "";
if (_showTitle) {
title = _stats.getProfession().getLabel();
}
updateData();
JFreeChart jfreechart = ChartFactory.createXYStepChart(title, "Time", "Tier", _data, PlotOrientation.VERTICAL, true, true, false);
Color foregroundColor = GuiFactory.getForegroundColor();
Paint backgroundPaint = GuiFactory.getBackgroundPaint();
jfreechart.setBackgroundPaint(backgroundPaint);
TextTitle t = new TextTitle(title);
t.setFont(t.getFont().deriveFont(24.0f));
t.setPaint(foregroundColor);
jfreechart.setTitle(t);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setDomainPannable(false);
XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES);
XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {
@Override
public String generateLabelString(XYDataset dataset, int series, int item) {
String label;
int tier = (int) dataset.getYValue(series, item);
if (tier == 0) {
label = "Started profession";
} else {
CraftingLevel level = CraftingLevel.getByTier(tier);
if (level != null) {
if (series == 0)
label = level.getMastery().getLabel();
else if (series == 1)
label = level.getProficiency().getLabel();
else
label = "???";
} else {
label = "???";
}
}
double timestamp = dataset.getXValue(series, item);
String date = Formats.getDateString(Long.valueOf((long) timestamp));
return label + " (" + date + ")";
}
};
xysteparearenderer.setBaseToolTipGenerator(tooltip);
xysteparearenderer.setSeriesPaint(0, new Color(255, 235, 31));
xysteparearenderer.setSeriesPaint(1, new Color(130, 80, 57));
xyplot.setRenderer(xysteparearenderer);
DateAxis axis = (DateAxis) xyplot.getDomainAxis();
SimpleDateFormat sdf = Formats.getDateFormatter();
axis.setDateFormatOverride(sdf);
axis.setAxisLinePaint(foregroundColor);
axis.setLabelPaint(foregroundColor);
axis.setTickLabelPaint(foregroundColor);
NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis();
valueAxis.setAutoRange(false);
valueAxis.setAxisLinePaint(foregroundColor);
valueAxis.setLabelPaint(foregroundColor);
valueAxis.setTickLabelPaint(foregroundColor);
CraftingLevel maxLevel = CraftingLevel.getMaximumLevel();
valueAxis.setRange(0, maxLevel.getTier());
NumberFormat nf = new NumberFormat() {
private String format(int number) {
CraftingLevel level = CraftingLevel.getByTier(number);
String ret = (level != null) ? level.getProficiency().getLabel() : "???";
return ret;
}
@Override
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
return toAppendTo.append(format((int) number));
}
@Override
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
return toAppendTo.append(format((int) number));
}
@Override
public Number parse(String source, ParsePosition parsePosition) {
return null;
}
};
valueAxis.setNumberFormatOverride(nf);
LegendTitle legend = jfreechart.getLegend();
legend.setItemPaint(foregroundColor);
legend.setBackgroundPaint(backgroundPaint);
return jfreechart;
}
use of org.jfree.chart.labels.XYToolTipGenerator in project lotro-companion by dmorcellet.
the class FactionHistoryChartController method buildChart.
private JFreeChart buildChart() {
String title = "";
if (_showTitle) {
title = _stats.getFaction().getName();
}
updateData();
JFreeChart jfreechart = ChartFactory.createXYStepChart(title, "Time", "Level", _data, PlotOrientation.VERTICAL, true, true, false);
Color foregroundColor = GuiFactory.getForegroundColor();
Paint backgroundPaint = GuiFactory.getBackgroundPaint();
jfreechart.setBackgroundPaint(backgroundPaint);
TextTitle t = new TextTitle(title);
t.setFont(t.getFont().deriveFont(24.0f));
t.setPaint(foregroundColor);
jfreechart.setTitle(t);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setDomainPannable(false);
XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES);
Faction faction = _stats.getFaction();
final FactionLevel[] levels = faction.getLevels();
XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {
@Override
public String generateLabelString(XYDataset dataset, int series, int item) {
String label = "???";
int tier = (int) dataset.getYValue(series, item);
for (FactionLevel level : levels) {
if (level.getValue() == tier) {
label = level.getName();
}
}
double timestamp = dataset.getXValue(series, item);
String date = Formats.getDateString(Long.valueOf((long) timestamp));
return label + " (" + date + ")";
}
};
xysteparearenderer.setBaseToolTipGenerator(tooltip);
xysteparearenderer.setSeriesPaint(0, new Color(0, 0, 255));
xyplot.setRenderer(xysteparearenderer);
DateAxis axis = (DateAxis) xyplot.getDomainAxis();
SimpleDateFormat sdf = Formats.getDateFormatter();
axis.setDateFormatOverride(sdf);
axis.setAxisLinePaint(foregroundColor);
axis.setLabelPaint(foregroundColor);
axis.setTickLabelPaint(foregroundColor);
NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis();
valueAxis.setAutoRange(false);
valueAxis.setAxisLinePaint(foregroundColor);
valueAxis.setLabelPaint(foregroundColor);
valueAxis.setTickLabelPaint(foregroundColor);
final int min = levels[0].getValue();
int max = levels[levels.length - 1].getValue();
valueAxis.setRange(min, max);
NumberFormat nf = new NumberFormat() {
private String format(int number) {
String ret = levels[number - min].getName();
return ret;
}
@Override
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
return toAppendTo.append(format((int) number));
}
@Override
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
return toAppendTo.append(format((int) number));
}
@Override
public Number parse(String source, ParsePosition parsePosition) {
return null;
}
};
valueAxis.setNumberFormatOverride(nf);
LegendTitle legend = jfreechart.getLegend();
legend.setItemPaint(foregroundColor);
legend.setBackgroundPaint(backgroundPaint);
return jfreechart;
}
Aggregations