Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 778 | blopes | 1 | package br.com.robo.view; |
| 2 | |||
| 3 | import br.com.robo.model.Candle; |
||
| 4 | import org.knowm.xchart.OHLCChart; |
||
| 5 | import org.knowm.xchart.OHLCChartBuilder; |
||
| 6 | import org.knowm.xchart.SwingWrapper; |
||
| 7 | |||
| 8 | import java.time.ZoneId; |
||
| 9 | import java.util.ArrayList; |
||
| 10 | import java.util.Date; |
||
| 11 | import java.util.List; |
||
| 12 | |||
| 13 | public class CandleChart { |
||
| 14 | |||
| 15 | public static void exibirCandles(List<Candle> candles, String titulo) { |
||
| 16 | |||
| 17 | List<Date> xData = new ArrayList<>(); |
||
| 18 | List<Double> open = new ArrayList<>(); |
||
| 19 | List<Double> high = new ArrayList<>(); |
||
| 20 | List<Double> low = new ArrayList<>(); |
||
| 21 | List<Double> close = new ArrayList<>(); |
||
| 22 | |||
| 23 | for (Candle c : candles) { |
||
| 24 | Date t = Date.from(c.getTime() |
||
| 25 | .atZone(ZoneId.systemDefault()) |
||
| 26 | .toInstant()); |
||
| 27 | xData.add(t); |
||
| 28 | open.add(c.getOpen()); |
||
| 29 | high.add(c.getHigh()); |
||
| 30 | low.add(c.getLow()); |
||
| 31 | close.add(c.getClose()); |
||
| 32 | } |
||
| 33 | |||
| 34 | OHLCChart chart = new OHLCChartBuilder() |
||
| 35 | .width(1200) |
||
| 36 | .height(700) |
||
| 37 | .title(titulo) |
||
| 38 | .xAxisTitle("Tempo") |
||
| 39 | .yAxisTitle("Preço") |
||
| 40 | .build(); |
||
| 41 | |||
| 42 | chart.addSeries("Simulado", xData, open, high, low, close); |
||
| 43 | |||
| 44 | new SwingWrapper<>(chart).displayChart(); |
||
| 45 | } |
||
| 46 | } |