use of org.jfree.chart.axis.DateAxis in project xwiki-platform by xwiki.
the class TimePlotFactory method create.
@Override
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
Class rendererClass = params.getClass(ChartParams.RENDERER);
XYItemRenderer renderer;
if (rendererClass != null) {
try {
Constructor ctor = rendererClass.getConstructor(new Class[] {});
renderer = (XYItemRenderer) ctor.newInstance(new Object[] {});
} catch (Throwable e) {
throw new GenerateException(e);
}
} else {
renderer = new XYLineAndShapeRenderer();
}
ChartCustomizer.customizeXYItemRenderer(renderer, params);
DateAxis domainAxis = new DateAxis();
ChartCustomizer.customizeDateAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX);
NumberAxis rangeAxis = new NumberAxis();
// override default
rangeAxis.setAutoRangeIncludesZero(false);
ChartCustomizer.customizeNumberAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX);
XYDataset dataset = TimeSeriesCollectionFactory.getInstance().create(dataSource, params);
XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
ChartCustomizer.customizeXYPlot(plot, params);
return plot;
}
use of org.jfree.chart.axis.DateAxis in project xwiki-platform by xwiki.
the class TableTimeTableXYBuilderTest method testBuildTimeTableXY.
@Test
public void testBuildTimeTableXY() throws Exception {
String content = "| Date | column 2 | column 3 | column 4\n" + "| 2012-01-01 10:30:10 | 12 | 13 | 14 \n" + "| 2012-01-01 10:30:20 | 22 | 23 | 24 \n";
setUpContentExpectation(content);
getDataSource().buildDataset(content, map("type", "xy_line_and_shape", "dataset", "timetable_xy", "range", "A2-D3", "locale", "en_US", "date_format", "yyyy-MM-dd kk:mm:ss", "domain_axis_type", "date"), null);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss", new Locale("en"));
ChartModel chartModel = getDataSource().getChartModel();
Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset);
Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis);
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
TimeTableXYDataset dataset = (TimeTableXYDataset) chartModel.getDataset();
Assert.assertTrue(dataset.getSeriesCount() == 3);
Assert.assertTrue(dataset.getSeriesKey(0).equals(" column 2 "));
Assert.assertTrue(dataset.getSeriesKey(1).equals(" column 3 "));
Assert.assertTrue(dataset.getSeriesKey(2).equals(" column 4"));
Assert.assertTrue(dataset.getTimePeriod(0).getStart().equals(new Date(0)));
Assert.assertTrue(dataset.getTimePeriod(0).getEnd().equals(dateFormat.parse("2012-01-01 10:30:10")));
Assert.assertTrue(dataset.getTimePeriod(1).getStart().equals(dateFormat.parse("2012-01-01 10:30:10")));
Assert.assertTrue(dataset.getTimePeriod(1).getEnd().equals(dateFormat.parse("2012-01-01 10:30:20")));
}
use of org.jfree.chart.axis.DateAxis in project xwiki-platform by xwiki.
the class TableTimeTableXYBuilderTest method testYearInterval.
@Test
public void testYearInterval() throws Exception {
String content = "| Date | column 2 | column 3 | column 4\n" + "| 1970 | 12 | 13 | 14 \n" + "| 1971 | 22 | 23 | 24 \n";
setUpContentExpectation(content);
getDataSource().buildDataset(content, map("type", "xy_line_and_shape", "dataset", "timetable_xy", "range", "A2-D3", "locale", "en_US", "date_format", "yyyy", "domain_axis_type", "date", "time_period", "year"), null);
ChartModel chartModel = getDataSource().getChartModel();
Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset);
Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis);
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
}
use of org.jfree.chart.axis.DateAxis in project ta4j by ta4j.
the class CashFlowToChart method main.
public static void main(String[] args) {
// Getting the time series
TimeSeries series = CsvTradesLoader.loadBitstampSeries();
// Building the trading strategy
Strategy strategy = MovingMomentumStrategy.buildStrategy(series);
// Running the strategy
TimeSeriesManager seriesManager = new TimeSeriesManager(series);
TradingRecord tradingRecord = seriesManager.run(strategy);
// Getting the cash flow of the resulting trades
CashFlow cashFlow = new CashFlow(series, tradingRecord);
/*
Building chart datasets
*/
TimeSeriesCollection datasetAxis1 = new TimeSeriesCollection();
datasetAxis1.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));
TimeSeriesCollection datasetAxis2 = new TimeSeriesCollection();
datasetAxis2.addSeries(buildChartTimeSeries(series, cashFlow, "Cash Flow"));
/*
Creating the chart
*/
JFreeChart chart = ChartFactory.createTimeSeriesChart(// title
"Bitstamp BTC", // x-axis label
"Date", // y-axis label
"Price", // data
datasetAxis1, // create legend?
true, // generate tooltips?
true, // generate URLs?
false);
XYPlot plot = (XYPlot) chart.getPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("MM-dd HH:mm"));
/*
Adding the cash flow axis (on the right)
*/
addCashFlowAxis(plot, datasetAxis2);
/*
Displaying the chart
*/
displayChart(chart);
}
use of org.jfree.chart.axis.DateAxis 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;
}
Aggregations