Search in sources :

Example 16 with ValueAxis

use of org.jfree.chart.axis.ValueAxis 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 17 with ValueAxis

use of org.jfree.chart.axis.ValueAxis 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 18 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project tdq-studio-se by Talend.

the class ChartDecorator method decorateCategoryPlot.

/**
 * DOC bZhou Comment method "decorateCategoryPlot".
 *
 * @param chart
 */
public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) {
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer render = plot.getRenderer();
    CategoryAxis domainAxis = plot.getDomainAxis();
    // ADD msjian TDQ-5111 2012-4-9: set something look it well
    domainAxis.setCategoryMargin(0.1);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);
    domainAxis.setCategoryLabelPositionOffset(10);
    // TDQ-5111~
    ValueAxis valueAxis = plot.getRangeAxis();
    // $NON-NLS-1$
    Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);
    render.setBaseItemLabelFont(font);
    // MOD zshen 10998: change the font name 2010-01-16
    // $NON-NLS-1$
    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);
    domainAxis.setLabelFont(font);
    // $NON-NLS-1$
    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);
    valueAxis.setLabelFont(font);
    // $NON-NLS-1$
    font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);
    domainAxis.setTickLabelFont(font);
    valueAxis.setTickLabelFont(font);
    setLegendFont(chart);
    // $NON-NLS-1$
    font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
    }
    font = null;
    if (render instanceof BarRenderer) {
        CategoryDataset dataset = chart.getCategoryPlot().getDataset();
        if (dataset != null) {
            int rowCount = dataset.getRowCount();
            List<?> columnKeys = dataset.getColumnKeys();
            if (!isContainCJKCharacter(columnKeys.toArray())) {
                // $NON-NLS-1$
                domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));
            }
            ((BarRenderer) render).setItemMargin(-0.40 * rowCount);
            // TDQ-12621 add Tooltip for Lable
            for (Object colKey : columnKeys) {
                domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString());
            }
        }
        domainAxis.setUpperMargin(0.1);
        // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..."
        domainAxis.setMaximumCategoryLabelLines(1);
        // not do this when the bar is horizontal Orientation
        if (orientation == null) {
            ((BarRenderer) render).setMaximumBarWidth(0.2);
        }
    // TDQ-5111~
    }
// ~10998
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Font(java.awt.Font) Paint(java.awt.Paint)

Example 19 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project tdq-studio-se by Talend.

the class ToolTipChartComposite method getTooltipAtPoint.

/**
 * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a
 * data point in a data set that lies inside a hotspot around that value.
 *
 * @param point The Java 2D point
 * @return A string for the data at the point or null if no data is found.
 */
protected String getTooltipAtPoint(Point point) {
    String result = null;
    Point2D translatedPoint = this.translateScreenToJava2D(point);
    Plot plot = this.getChart().getPlot();
    PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo();
    if (plot instanceof CombinedDomainXYPlot) {
        int index = info.getSubplotIndex(translatedPoint);
        if (index < 0) {
            index = 0;
        }
        plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index);
        info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index);
    }
    if (plot != null && plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        ValueAxis domainAxis = xyPlot.getDomainAxis();
        ValueAxis rangeAxis = xyPlot.getRangeAxis();
        // had to switch to SWT's rectangle here.
        Rectangle screenArea = this.scale(info.getDataArea());
        double hotspotSizeX = hotspontsize * this.getScaleX();
        double hotspotSizeY = hotspontsize * this.getScaleY();
        double x0 = point.getX();
        double y0 = point.getY();
        double x1 = x0 - hotspotSizeX;
        double y1 = y0 + hotspotSizeY;
        double x2 = x0 + hotspotSizeX;
        double y2 = y0 - hotspotSizeY;
        RectangleEdge xEdge = RectangleEdge.BOTTOM;
        RectangleEdge yEdge = RectangleEdge.LEFT;
        // Switch everything for horizontal charts
        if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) {
            hotspotSizeX = hotspontsize * this.getScaleY();
            hotspotSizeY = hotspontsize * this.getScaleX();
            x0 = point.getY();
            y0 = point.getX();
            x1 = x0 + hotspotSizeX;
            y1 = y0 - hotspotSizeY;
            x2 = x0 - hotspotSizeX;
            y2 = y0 + hotspotSizeY;
            xEdge = RectangleEdge.LEFT;
            yEdge = RectangleEdge.BOTTOM;
        }
        // OK, here we have to get ourselves back into AWT land...
        Rectangle2D r2d = new Rectangle2D.Double();
        r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height);
        double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge);
        double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge);
        double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge);
        double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge);
        double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge);
        int datasetCount = xyPlot.getDatasetCount();
        for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) {
            XYDataset dataset = xyPlot.getDataset(datasetIndex);
            int seriesCount = dataset.getSeriesCount();
            for (int series = 0; series < seriesCount; series++) {
                int itemCount = dataset.getItemCount(series);
                if (dataset instanceof OHLCDataset) {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item);
                        double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item);
                        // Check hi lo and swap if needed
                        if (yValueHi < yValueLo) {
                            double temp = yValueHi;
                            yValueHi = yValueLo;
                            yValueLo = temp;
                        }
                        // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the cursor 'y' value lies between the high and low (low < ty0 < high)
                            if (yValueLo < ty0 && ty0 < yValueHi) {
                                return hiLoTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                } else {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValue = dataset.getYValue(series, item);
                        // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2)
                            if (ty1 < yValue && yValue < ty2) {
                                return xyTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : PlotRenderingInfo(org.jfree.chart.plot.PlotRenderingInfo) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Plot(org.jfree.chart.plot.Plot) Rectangle(org.eclipse.swt.graphics.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) Point(java.awt.Point) OHLCDataset(org.jfree.data.xy.OHLCDataset) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) XYDataset(org.jfree.data.xy.XYDataset) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 20 with ValueAxis

use of org.jfree.chart.axis.ValueAxis in project evosuite by EvoSuite.

the class Plot method createGraph.

@Override
protected JFreeChart createGraph() {
    final JFreeChart chart = ChartFactory.createLineChart(null, "Build Number #", this.yLabel, this.dataset, PlotOrientation.VERTICAL, true, true, true);
    chart.setBackgroundPaint(Color.WHITE);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setBackgroundPaint(Color.WHITE);
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // yAxis.setRange(0.0, 100.0);
    URLAndTooltipRenderer urlRenderer = new URLAndTooltipRenderer(this.project.getProject());
    ColorPalette.apply(urlRenderer);
    plot.setRenderer(urlRenderer);
    return chart;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Aggregations

ValueAxis (org.jfree.chart.axis.ValueAxis)182 XYPlot (org.jfree.chart.plot.XYPlot)52 NumberAxis (org.jfree.chart.axis.NumberAxis)44 JFreeChart (org.jfree.chart.JFreeChart)37 CategoryPlot (org.jfree.chart.plot.CategoryPlot)35 Paint (java.awt.Paint)31 CategoryAxis (org.jfree.chart.axis.CategoryAxis)30 Test (org.junit.Test)24 Rectangle2D (java.awt.geom.Rectangle2D)20 Iterator (java.util.Iterator)20 XYDataset (org.jfree.data.xy.XYDataset)20 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)18 Range (org.jfree.data.Range)18 CategoryDataset (org.jfree.data.category.CategoryDataset)17 RectangleEdge (org.jfree.ui.RectangleEdge)16 XYSeries (org.jfree.data.xy.XYSeries)14 Font (java.awt.Font)13 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)13 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)13 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)13