use of org.jfree.chart.axis.DateAxis 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.axis.DateAxis 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.axis.DateAxis in project pinot by linkedin.
the class AnomalyGraphGenerator method createChart.
/**
* Creates a chart containing the current/baseline data (in that order) as well as markers for
* each anomaly interval. timeGranularity and windowMillis are used to determine the date format
* and spacing for tick marks on the domain (x) axis.
*/
public JFreeChart createChart(final XYDataset dataset, final String metric, final TimeGranularity timeGranularity, final long windowMillis, final Map<RawAnomalyResultDTO, String> anomaliesWithLabels) {
// create the chart...
final JFreeChart chart = // no chart title for email
ChartFactory.createTimeSeriesChart(// no chart title for email
null, // x axis label
"Date (" + DEFAULT_TIME_ZONE.getID() + ")", // y axis label
metric, // data
dataset, // include legend
true, // tooltips - n/a if the chart will be saved as an img
false, // urls - n/a if the chart will be saved as an img
false);
// get a reference to the plot for further customisation...
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
// dashboard webapp currently uses solid blue for current and dashed blue for baseline
// (5/2/2016)
final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesShapesVisible(0, false);
renderer.setSeriesShapesVisible(1, false);
renderer.setSeriesPaint(0, Color.BLUE);
renderer.setSeriesPaint(1, Color.BLUE);
// http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo5showingtheuseofacustomdrawingsupplier.htm
// set baseline to be dashed
renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
plot.setRenderer(renderer);
DateAxis axis = (DateAxis) plot.getDomainAxis();
DateTickUnit dateTickUnit = getDateTickUnit(timeGranularity, windowMillis);
SimpleDateFormat dateFormat = getDateFormat(timeGranularity);
axis.setDateFormatOverride(dateFormat);
axis.setTickUnit(dateTickUnit);
axis.setVerticalTickLabels(true);
List<Marker> anomalyIntervals = getAnomalyIntervals(anomaliesWithLabels);
for (Marker marker : anomalyIntervals) {
plot.addDomainMarker(marker);
}
return chart;
}
use of org.jfree.chart.axis.DateAxis in project dubbo by alibaba.
the class SimpleMonitorService method createChart.
private static void createChart(String key, String service, String method, String date, String[] types, Map<String, long[]> data, double[] summary, String path) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
DecimalFormat numberFormat = new DecimalFormat("###,##0.##");
TimeSeriesCollection xydataset = new TimeSeriesCollection();
for (int i = 0; i < types.length; i++) {
String type = types[i];
TimeSeries timeseries = new TimeSeries(type);
for (Map.Entry<String, long[]> entry : data.entrySet()) {
try {
timeseries.add(new Minute(dateFormat.parse(date + entry.getKey())), entry.getValue()[i]);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
}
xydataset.addSeries(timeseries);
}
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("max: " + numberFormat.format(summary[0]) + (summary[1] >= 0 ? " min: " + numberFormat.format(summary[1]) : "") + " avg: " + numberFormat.format(summary[2]) + (summary[3] >= 0 ? " sum: " + numberFormat.format(summary[3]) : ""), toDisplayService(service) + " " + method + " " + toDisplayDate(date), key, xydataset, true, true, false);
jfreechart.setBackgroundPaint(Color.WHITE);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinePaint(Color.GRAY);
xyplot.setRangeGridlinePaint(Color.GRAY);
xyplot.setDomainGridlinesVisible(true);
xyplot.setRangeGridlinesVisible(true);
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
BufferedImage image = jfreechart.createBufferedImage(600, 300);
try {
if (logger.isInfoEnabled()) {
logger.info("write chart: " + path);
}
File methodChartFile = new File(path);
File methodChartDir = methodChartFile.getParentFile();
if (methodChartDir != null && !methodChartDir.exists()) {
methodChartDir.mkdirs();
}
FileOutputStream output = new FileOutputStream(methodChartFile);
try {
ImageIO.write(image, "png", output);
output.flush();
} finally {
output.close();
}
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
use of org.jfree.chart.axis.DateAxis in project cubrid-manager by CUBRID.
the class HostDashboardViewPart method loadBrokerChart.
/**
* Load an instance of ChartCompositePart stand for broker monitor info
*
* @param parent the instance of Composite
*/
private void loadBrokerChart(Composite parent) {
brokerComp = new Composite(parent, SWT.NULL);
brokerComp.setLayout(new GridLayout());
brokerComp.setLayoutData(new GridData(GridData.FILL_BOTH));
Group brokerGrp = new Group(brokerComp, SWT.NONE);
brokerGrp.setText(Messages.hostBrokerSeriesGroupName);
GridLayout layoutGrp = new GridLayout();
layoutGrp.verticalSpacing = 0;
layoutGrp.horizontalSpacing = 0;
layoutGrp.marginLeft = 0;
layoutGrp.marginRight = 0;
layoutGrp.marginTop = 0;
layoutGrp.marginBottom = 0;
brokerGrp.setLayout(layoutGrp);
GridData gridData = new GridData(GridData.FILL_BOTH);
brokerGrp.setLayoutData(gridData);
BrokerDiagData brokerDiagData = new BrokerDiagData();
TreeMap<String, String> map = convertMapKey(brokerDiagData.getDiagStatusResultMap());
brokerChartPart = new ChartCompositePart(brokerGrp, map);
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
ShowSetting showSetting = brokerChartPart.getSettingMap().get(key);
ShowSettingMatching.match(key, showSetting, MonitorType.BROKER);
}
brokerChartPart.loadContent();
JFreeChart chart = (JFreeChart) brokerChartPart.getChart();
chart.setBorderVisible(false);
XYPlot xyplot = (XYPlot) brokerChartPart.getChart().getPlot();
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setFixedAutoRange(300000d);
dateaxis.setLowerMargin(0.0D);
dateaxis.setUpperMargin(0.0D);
dateaxis.setVisible(false);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
renderer.setURLGenerator(null);
renderer.setBaseToolTipGenerator(null);
}
Aggregations