Search in sources :

Example 16 with DateAxis

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;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) Constructor(java.lang.reflect.Constructor) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) XYDataset(org.jfree.data.xy.XYDataset) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException)

Example 17 with DateAxis

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")));
}
Also used : Locale(java.util.Locale) DateAxis(org.jfree.chart.axis.DateAxis) TimeTableXYDataset(org.jfree.data.time.TimeTableXYDataset) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartModel(org.xwiki.chart.model.ChartModel) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 18 with DateAxis

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);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) TimeTableXYDataset(org.jfree.data.time.TimeTableXYDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

Example 19 with DateAxis

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);
}
Also used : CashFlow(org.ta4j.core.analysis.CashFlow) DateAxis(org.jfree.chart.axis.DateAxis) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) MovingMomentumStrategy(ta4jexamples.strategies.MovingMomentumStrategy) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) SimpleDateFormat(java.text.SimpleDateFormat) JFreeChart(org.jfree.chart.JFreeChart)

Example 20 with DateAxis

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;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) TickUnitSource(org.jfree.chart.axis.TickUnitSource) LegendTitle(org.jfree.chart.title.LegendTitle) Paint(java.awt.Paint) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint) TextTitle(org.jfree.chart.title.TextTitle) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

DateAxis (org.jfree.chart.axis.DateAxis)39 XYPlot (org.jfree.chart.plot.XYPlot)33 JFreeChart (org.jfree.chart.JFreeChart)30 SimpleDateFormat (java.text.SimpleDateFormat)21 NumberAxis (org.jfree.chart.axis.NumberAxis)18 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)13 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)13 Color (java.awt.Color)10 DateFormat (java.text.DateFormat)8 Date (java.util.Date)7 Map (java.util.Map)7 ValueAxis (org.jfree.chart.axis.ValueAxis)7 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)7 BasicStroke (java.awt.BasicStroke)5 TreeMap (java.util.TreeMap)5 DateTickUnit (org.jfree.chart.axis.DateTickUnit)5 TimeSeries (org.jfree.data.time.TimeSeries)5 ChartCompositePart (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ChartCompositePart)4 HistoryComposite (com.cubrid.cubridmanager.ui.monitoring.editor.internal.HistoryComposite)4 ShowSetting (com.cubrid.cubridmanager.ui.monitoring.editor.internal.ShowSetting)4