use of org.jfree.chart.renderer.xy.XYStepAreaRenderer 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.renderer.xy.XYStepAreaRenderer 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;
}
use of org.jfree.chart.renderer.xy.XYStepAreaRenderer 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.renderer.xy.XYStepAreaRenderer in project SIMVA-SoS by SESoS.
the class ChartFactory method createXYStepAreaChart.
/**
* Creates a filled stepped XY plot with default settings.
*
* @param title the chart title (<code>null</code> permitted).
* @param xAxisLabel a label for the X-axis (<code>null</code> permitted).
* @param yAxisLabel a label for the Y-axis (<code>null</code> permitted).
* @param dataset the dataset for the chart (<code>null</code> permitted).
* @param orientation the plot orientation (horizontal or vertical)
* (<code>null</code> NOT permitted).
* @param legend a flag specifying whether or not a legend is required.
* @param tooltips configure chart to generate tool tips?
* @param urls configure chart to generate URLs?
*
* @return A chart.
*/
public static JFreeChart createXYStepAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {
ParamChecks.nullNotPermitted(orientation, "orientation");
NumberAxis xAxis = new NumberAxis(xAxisLabel);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisLabel);
XYToolTipGenerator toolTipGenerator = null;
if (tooltips) {
toolTipGenerator = new StandardXYToolTipGenerator();
}
XYURLGenerator urlGenerator = null;
if (urls) {
urlGenerator = new StandardXYURLGenerator();
}
XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, urlGenerator);
XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
plot.setRenderer(renderer);
plot.setOrientation(orientation);
plot.setDomainCrosshairVisible(false);
plot.setRangeCrosshairVisible(false);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
currentTheme.apply(chart);
return chart;
}
use of org.jfree.chart.renderer.xy.XYStepAreaRenderer 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;
}
Aggregations