如何使用 Java prefuse 库创建条形图?

发布于 2024-07-18 06:06:33 字数 634 浏览 3 评论 0原文

我目前有 prefuse 来绘制散点图,其中 X 轴是计算机名称,Y 轴是它的温度。 如何让它绘制显示值而不是离散点的条形?

我目前正在使用以下代码来渲染点:

ShapeAction shape = new ShapeAction(group, Constants.SHAPE_RECTANGLE);
ColorAction strokeColor = new DataColorAction(group, dataType, Constants.NUMERICAL, VisualItem.STROKECOLOR, colorPalette);

ActionList draw = new ActionList();
draw.add(shape);
draw.add(strokeColor);
draw.add(new ColorAction(group, VisualItem.FILLCOLOR, 0));
draw.add(new RepaintAction());
m_vis.putAction("draw", draw);

我如何调整此代码以获得从图表底部到该点的粗条,而不是每个点上的小方块?

谢谢。

I've currently got prefuse to plot a scatter graph, where the X axis is the computer name and the Y axis is its temperature. How do I get it to draw bars showing the values instead of discrete points?

I'm currently using the following code to render the points:

ShapeAction shape = new ShapeAction(group, Constants.SHAPE_RECTANGLE);
ColorAction strokeColor = new DataColorAction(group, dataType, Constants.NUMERICAL, VisualItem.STROKECOLOR, colorPalette);

ActionList draw = new ActionList();
draw.add(shape);
draw.add(strokeColor);
draw.add(new ColorAction(group, VisualItem.FILLCOLOR, 0));
draw.add(new RepaintAction());
m_vis.putAction("draw", draw);

How would I adapt this code to get, instead of a small square at each point, a thick bar going from th bottom of the graph to the point?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2024-07-25 06:06:33

我想我应该指出我是如何做到这一点的 - 毕竟 Stack Overflow 也应该是一个存储库。 前面的代码如下:

m_vis.setRendererFactory(new RendererFactory() {
    Renderer yAxisRenderer = new AxisRenderer(Constants.LEFT, Constants.TOP);
    Renderer xAxisRenderer = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);
    Renderer barRenderer = new ShapeRenderer();

    public Renderer getRenderer(VisualItem item) {
        return item.isInGroup("yAxis") ? yAxisRenderer :
               item.isInGroup("xAxis") ? xAxisRenderer :
               barRenderer;
    }
});

我扩展了形状渲染器,使其始终返回正确宽度和高度的矩形,并将其放置在其应有位置左侧半个栏的位置。 如果你想把你的酒吧放在中心,你需要自己做 - prefuse 不会帮助你。

m_vis.setRendererFactory(new RendererFactory() {
    Renderer yAxisRenderer = new AxisRenderer(Constants.LEFT, Constants.TOP);
    Renderer xAxisRenderer = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);
    Renderer barRenderer = new ShapeRenderer() {
        protected Shape getRawShape(VisualItem item) {
            double x = item.getX();
            double y = item.getY();
            if (Double.isNaN(x) || Double.isInfinite(x))
                x = getInsets().left + axisWidth + totalBarWidth / 2;
            if (Double.isNaN(y) || Double.isInfinite(y))
                y = 0;

            double width = totalBarWidth / (barCount + 1) - barGap;
            double height = getHeight() - getInsets().bottom - axisHeight - y;
            x -= width / 2;

            return rectangle(x, y, width, height);
        }
    };

    public Renderer getRenderer(VisualItem item) {
        return item.isInGroup("yAxis") ? yAxisRenderer :
               item.isInGroup("xAxis") ? xAxisRenderer :
               barRenderer;
    }
});

I think I should probably point out how I did this - Stack Overflow is supposed to be a repository too, after all. Earlier in the code was the following:

m_vis.setRendererFactory(new RendererFactory() {
    Renderer yAxisRenderer = new AxisRenderer(Constants.LEFT, Constants.TOP);
    Renderer xAxisRenderer = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);
    Renderer barRenderer = new ShapeRenderer();

    public Renderer getRenderer(VisualItem item) {
        return item.isInGroup("yAxis") ? yAxisRenderer :
               item.isInGroup("xAxis") ? xAxisRenderer :
               barRenderer;
    }
});

I extended the shape renderer to always return a rectangle of the correct width and height, and positioned it half a bar to the left of where it was supposed to be. If you want to position your bars in the centre, you need to do that yourself - prefuse won't help you.

m_vis.setRendererFactory(new RendererFactory() {
    Renderer yAxisRenderer = new AxisRenderer(Constants.LEFT, Constants.TOP);
    Renderer xAxisRenderer = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);
    Renderer barRenderer = new ShapeRenderer() {
        protected Shape getRawShape(VisualItem item) {
            double x = item.getX();
            double y = item.getY();
            if (Double.isNaN(x) || Double.isInfinite(x))
                x = getInsets().left + axisWidth + totalBarWidth / 2;
            if (Double.isNaN(y) || Double.isInfinite(y))
                y = 0;

            double width = totalBarWidth / (barCount + 1) - barGap;
            double height = getHeight() - getInsets().bottom - axisHeight - y;
            x -= width / 2;

            return rectangle(x, y, width, height);
        }
    };

    public Renderer getRenderer(VisualItem item) {
        return item.isInGroup("yAxis") ? yAxisRenderer :
               item.isInGroup("xAxis") ? xAxisRenderer :
               barRenderer;
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文