简体   繁体   English

可滚动的JFree域轴和自定义标记标签

[英]Scrollable JFree domain axis and custom marker label

I have this code to draw graph, this works fine. 我有这个代码来绘制图形,这很好用。 I need two things here 我这里需要两件事

  1. on domain axis (x) I want to be able to scroll. 在域轴(x)我希望能够滚动。
  2. On markers I see a thick bold line. 在标记上,我看到粗粗线。 I want to be able to see some readable text for this marker. 我希望能够看到这个标记的一些可读文本。

For now I see this output 现在我看到这个输出 在此输入图像描述

and upon zooming I see this 在缩放时,我看到了这一点

在此输入图像描述

  1. Also on domain axis I have millis values. 同样在域轴上我有毫秒值。 can I map it to human readable dates ? 我可以将它映射到人类可读的日期吗?

     public class Grapher extends ApplicationFrame { public Grapher(final String title, List<PriceModel> priceModels) { super(title); final XYSeries series = new XYSeries("foo"); double max = Double.MIN_VALUE, min = Double.MAX_VALUE; for (int i = 0; i < priceModels.size(); i++) { double price = priceModels.get(i).getPrice(); if (price < min) { min = price; } if (price > max) { max = price; } series.add((double) priceModels.get(i).getDate(), price); } final XYSeriesCollection data = new XYSeriesCollection(series); final JFreeChart chart = ChartFactory.createXYLineChart( "XY Series Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false ); for (int i = 0; i < priceModels.size(); i++) { if (priceModels.get(i).getAction() != null) { Marker marker = new ValueMarker((double) priceModels.get(i).getDate()); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); if (priceModels.get(i).getAction() == Types.Action.SELL) { marker.setPaint(Color.green); marker.setLabel("SELL"); } else { marker.setPaint(Color.red); marker.setLabel("BUY"); } marker.setStroke(new BasicStroke(10.0f)); chart.getXYPlot().addDomainMarker(marker); } } chart.getXYPlot().setBackgroundPaint(Color.white); chart.getXYPlot().getRenderer().setPaint(Color.BLUE); chart.getXYPlot().getRangeAxis().setRange(min - 1, max + 1); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBackground(Color.WHITE); chartPanel.setRangeZoomable(true); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); } public static void draw(List<PriceModel> priceModels) { final Grapher demo = new Grapher("foo", priceModels); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); } } 

You'll have to combine several approaches: 你必须结合几种方法:

  1. Domain scrolling alternatives : 域名滚动替代方案

  2. Marker text : Use XYTextAnnotation , for example . 标记文本例如 ,使用XYTextAnnotation

  3. Format dates : Replace the factory's axis with a DateAxis and use setDateFormatOverride() , for example . 格式日期 :用更换工厂的轴DateAxis和使用setDateFormatOverride()例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM