Blame |
Last modification |
View Log
| Download
| RSS feed
package br.com.robo.view;
import br.com.robo.model.Candle;
import org.knowm.xchart.OHLCChart;
import org.knowm.xchart.OHLCChartBuilder;
import org.knowm.xchart.SwingWrapper;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class CandleChart
{
public static void exibirCandles
(List<Candle
> candles,
String titulo
) {
List<Date> xData =
new ArrayList<>();
List<Double> open =
new ArrayList<>();
List<Double> high =
new ArrayList<>();
List<Double> low =
new ArrayList<>();
List<Double> close =
new ArrayList<>();
for (Candle c : candles
) {
Date t =
Date.
from(c.
getTime()
.
atZone(ZoneId.
systemDefault())
.
toInstant());
xData.
add(t
);
open.
add(c.
getOpen());
high.
add(c.
getHigh());
low.
add(c.
getLow());
close.
add(c.
getClose());
}
OHLCChart chart =
new OHLCChartBuilder
()
.
width(1200)
.
height(700)
.
title(titulo
)
.
xAxisTitle("Tempo")
.
yAxisTitle("Preço")
.
build();
chart.
addSeries("Simulado", xData, open, high, low, close
);
new SwingWrapper
<>(chart
).
displayChart();
}
}