可滚动的JFree域轴和自定义标记标签 [英] Scrollable JFree domain axis and custom marker label
本文介绍了可滚动的JFree域轴和自定义标记标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码可以绘制图形,效果很好.我需要两件事
- 在域轴(x)上,我希望能够滚动.
- 在标记上,我看到粗线.我希望能够看到此标记的一些可读文本.
现在我看到此输出
缩放后,我看到了
-
在域轴上,我也具有毫秒值.我可以将其映射到人类可读的日期吗?
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); } }
解决方案
您将不得不结合几种方法:
-
域滚动选项:
- 尝试使用已实现
SlidingXYDataset
/patches/231/"rel =" nofollow noreferrer>此处,并在此处进行说明. - 启用平移,例如
plot.setDomainPannable(true)
,如建议的此处. - 查看分页.
- 使用
JScrollPane
,例如add(new JScrollPane(chartPanel);
.
- 尝试使用已实现
-
标记文字:对于示例,使用
XYTextAnnotation
.. p>
解决方案
You'll have to combine several approaches:
Domain scrolling alternatives:
- Try a
SlidingXYDataset
, implemented here and illustrated here. - Enable panning, e.g.
plot.setDomainPannable(true)
, as suggested here. - Look at paging.
- Use a
JScrollPane
, e.g.add(new JScrollPane(chartPanel);
.
- Try a
Marker text: Use
XYTextAnnotation
, for example.Format dates: Replace the factory's axis with a
DateAxis
and usesetDateFormatOverride()
, for example.
这篇关于可滚动的JFree域轴和自定义标记标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文