JFreechart 在刻度上渲染时间序列

发布于 2024-07-27 12:38:21 字数 287 浏览 3 评论 0原文

我有一个数据时间序列,我想在刻度尺而不是时间刻度上绘制。

例如,如果该系列包含在以下时间收到的点:10、15、30、100。我不想将这些点绘制在常规时间序列轴上,其中 30 点和 100 点之间的距离为 70,我希望每个点之间的距离这些点为1 个单位。 本质上,我想在基础数据集中的点索引处绘制点。

这可以在 JFreechart 中轻松完成吗?

我尝试过实现自己的时间线,但它变得混乱。 我还希望标签反映时间而不是刻度数。

I have a timeseries of data which i'd like to plot on a tick scale rather than a time scale.

e.g. If the series contains points received at times: 10, 15, 30, 100. Instead of plotting these against a regular time series axis where the distance between the 30 and 100 point would be 70, i'd like the distance between each of these points to be 1 unit. Essentially I want to plot the points at the points index in the underlying dataset.

Can this be easily done in JFreechart.

I've had a go at implementing my own Timeline but it's getting messy. I'd also like the labels to reflect the time and not the tick number.

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

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

发布评论

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

评论(2

苦笑流年记忆 2024-08-03 12:38:21

我不知道如何使用具有时间坐标的数据元素创建图表,然后在绘制它们时忽略时间,但是当您创建 TimePeriodValues 时,您可以对由数据点表示的 TimePeriod 撒谎为了让 JFreechart 相信它们是规则间隔的。 当然,这意味着您必须手动预处理数据以对其进行排序,以便按顺序对事件进行编号(除非您已经有与该系列关联的事件编号?)

我不知道如何显示除了轴上的 x 坐标之外的其他值,但您可以在每个数据点旁边显示一个标签。 (演示集中的注释演示演示了如何操作。)

I don't know of a way to create a chart with data elements that have a time coordinate and then to ignore the times when plotting them, but when you are creating your TimePeriodValues, you can lie about the TimePeriod represented by the data point in order to convince JFreechart that they are regularly spaced. Of course, this means that you'll have to manually pre-process the data to sort it in order to number the events sequentially (unless you already have event numbers associated with the series?)

I don't know of a way to display something other than the x-coordinate on the axis, but you can display a label next to each data point. (The Annotation demo in the demo collection shows how.)

幽梦紫曦~ 2024-08-03 12:38:21

我通过使用 NumericAxis 而不是 DateAxis 处理了同样的事情,然后重写刷新TicksHorizo​​ntal 方法来构建 NumericTicks 列表,但标签格式为日期。 这有点麻烦,但为我完成了工作。

    NumberAxis domainAxis = new NumberAxis("Date") {
        @Override
        protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
            List ticks = new ArrayList();
            //you'll need to have corresponding date objects around
            //or know how to match them up on the graph
            for (int i = 0; i < dates.size(); i++) {
                String label = dateFormat.format(dates.get(i));
                NumberTick tick = new NumberTick(i, label, TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0);
                ticks.add(tick);                    
            }
            return ticks;
        }
    };

I handled this same thing by using a NumericAxis instead of a DateAxis and then overriding the refreshTicksHorizontal method to build a list of NumericTicks but with label formatted as dates. It was a bit of a hack, but got the job done for me.

    NumberAxis domainAxis = new NumberAxis("Date") {
        @Override
        protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
            List ticks = new ArrayList();
            //you'll need to have corresponding date objects around
            //or know how to match them up on the graph
            for (int i = 0; i < dates.size(); i++) {
                String label = dateFormat.format(dates.get(i));
                NumberTick tick = new NumberTick(i, label, TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0);
                ticks.add(tick);                    
            }
            return ticks;
        }
    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文