【问题标题】:JFreeChart incorrect tooltips positionJFreeChart 不正确的工具提示位置
【发布时间】:2012-09-27 08:17:16
【问题描述】:

jfreechart 1.0.13

我对 jfreechart 中工具提示的位置有一些问题。 我通过以下配置构建它

 private static final GradientPaint GRADIENT_PAINT = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));

    private static final double ITEM_MARGIN = 0.2d;

    private static final double MAXIMUM_BAR_WIDTH = .04;

    private static final int MAXIMUM_CATEGORY_LABEL_WIDTH = 10;

    private static final int MAXIMUM_CATEGORY_LABEL_LINES = 2;

    private static final Paint BACKGROUND_COLOR = new Color(196, 196, 196);

 @Override
    protected BarRenderer configMainRenderer() {
        BarRenderer renderer = new BarRenderer();
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderer.setShadowVisible(false);
        renderer.setDrawBarOutline(false);
        renderer.setDrawBarOutline(true);
        renderer.setMaximumBarWidth(MAXIMUM_BAR_WIDTH);
        renderer.setSeriesPaint(0, GRADIENT_PAINT);
        renderer.setItemMargin(ITEM_MARGIN);
        return renderer;
    }

 @Override
    protected NumberAxis configRangeAxis(IRangeAxis axis) {
        NumberAxis valueAxis = new NumberAxis(axis.getName());
        valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        return valueAxis;
    }

@Override
protected CategoryAxis configDomainAxis(String domainAxisName) {
    CategoryAxis domainAxis = new CategoryAxis(domainAxisName);
    domainAxis.setMaximumCategoryLabelWidthRatio(MAXIMUM_CATEGORY_LABEL_WIDTH);
    domainAxis.setMaximumCategoryLabelLines(MAXIMUM_CATEGORY_LABEL_LINES);
    domainAxis.setTickLabelFont(getDefaultDomainAxisFont());
    return domainAxis;
}

@Override
protected CategoryPlot plotSetup(Dataset dataset, CategoryAxis domainAxis, NumberAxis mainRangeAxis, BarRenderer mainRenderer) {
    CategoryDataset catDataset = (CategoryDataset)dataset;
    CategoryPlot plot = new CategoryPlot(catDataset, domainAxis, mainRangeAxis, mainRenderer);
    plot.setOrientation(getModel().getPlotOrientation());
    plot.setBackgroundPaint(BACKGROUND_COLOR);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    return plot;

然后我将新创建的图表放入 ChartComposite 视图中。

//creating composite for chart
        chartComposite = new ChartComposite(controlsComposite, SWT.NONE);
        chartComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        chartComposite.setVisible(false);
        chartComposite.addChartMouseListener(this);
// update chartcomposite when necessary
        chartComposite.setVisible(true);
        chartComposite.setChart(chart);
        chartComposite.setHorizontalAxisTrace(true);
        chartComposite.forceRedraw();

结果我有正确的图表,但所有工具提示都移到了视图/合成的右侧。此外,当我尝试选择一些图表区域时 - 选择不是从“0”点开始,但似乎也发生了变化。(见附图)

我很高兴听到有关此类行为的任何建议

【问题讨论】:

  • 这是swt 的问题吗?另请参阅answer

标签: java eclipse tooltip jfreechart rcp


【解决方案1】:

我也有工具提示的错误。 我想出的解决办法:

1) 在 JFreeChart 的源代码中找到文件 ChartComposite.java 2)在第1200行(大约)找到

    ChartEntity entity = entities.getEntity(
    e.x - insets.x /this.scaleX, 
    y.x - insets.y /this.scaleY);

并像这样删除比例:

    ChartEntity entity = entities.getEntity(
    (e.x - insets.x), 
    (y.x - insets.y));

希望对你有帮助。

注意

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多