Search in sources :

Example 1 with CandleStickChart

use of io.bitsquare.gui.main.market.trades.charts.price.CandleStickChart in project bitsquare by bitsquare.

the class TradesChartsView method createCharts.

///////////////////////////////////////////////////////////////////////////////////////////
// Chart
///////////////////////////////////////////////////////////////////////////////////////////
private void createCharts() {
    priceSeries = new XYChart.Series<>();
    priceAxisX = new NumberAxis(0, model.maxTicks + 1, 1);
    priceAxisX.setTickUnit(1);
    priceAxisX.setMinorTickCount(0);
    priceAxisX.setForceZeroInRange(false);
    priceAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    priceAxisY = new NumberAxis();
    priceAxisY.setForceZeroInRange(false);
    priceAxisY.setAutoRanging(true);
    priceAxisY.setTickLabelFormatter(new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
                final double value = MathUtils.scaleDownByPowerOf10((double) object, 8);
                return formatter.formatRoundedDoubleWithPrecision(value, 8);
            } else
                return formatter.formatPrice(Fiat.valueOf(model.getCurrencyCode(), MathUtils.doubleToLong((double) object)));
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    priceChart = new CandleStickChart(priceAxisX, priceAxisY, new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
                final double value = MathUtils.scaleDownByPowerOf10((long) object, 8);
                return formatter.formatRoundedDoubleWithPrecision(value, 8);
            } else {
                return formatter.formatPrice(Fiat.valueOf(model.getCurrencyCode(), (long) object));
            }
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    priceChart.setMinHeight(198);
    priceChart.setPrefHeight(198);
    priceChart.setMaxHeight(300);
    priceChart.setLegendVisible(false);
    priceChart.setData(FXCollections.observableArrayList(priceSeries));
    volumeSeries = new XYChart.Series<>();
    volumeAxisX = new NumberAxis(0, model.maxTicks + 1, 1);
    volumeAxisX.setTickUnit(1);
    volumeAxisX.setMinorTickCount(0);
    volumeAxisX.setForceZeroInRange(false);
    volumeAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    volumeAxisY = new NumberAxis();
    volumeAxisY.setForceZeroInRange(true);
    volumeAxisY.setAutoRanging(true);
    volumeAxisY.setLabel("Volume in BTC");
    volumeAxisY.setTickLabelFormatter(new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            return formatter.formatCoin(Coin.valueOf(MathUtils.doubleToLong((double) object)));
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    volumeChart = new VolumeChart(volumeAxisX, volumeAxisY, new StringConverter<Number>() {

        @Override
        public String toString(Number object) {
            return formatter.formatCoinWithCode(Coin.valueOf((long) object));
        }

        @Override
        public Number fromString(String string) {
            return null;
        }
    });
    volumeChart.setData(FXCollections.observableArrayList(volumeSeries));
    volumeChart.setMinHeight(148);
    volumeChart.setPrefHeight(148);
    volumeChart.setMaxHeight(200);
    volumeChart.setLegendVisible(false);
}
Also used : VolumeChart(io.bitsquare.gui.main.market.trades.charts.volume.VolumeChart) NumberAxis(javafx.scene.chart.NumberAxis) XYChart(javafx.scene.chart.XYChart) StringConverter(javafx.util.StringConverter) CandleStickChart(io.bitsquare.gui.main.market.trades.charts.price.CandleStickChart)

Aggregations

CandleStickChart (io.bitsquare.gui.main.market.trades.charts.price.CandleStickChart)1 VolumeChart (io.bitsquare.gui.main.market.trades.charts.volume.VolumeChart)1 NumberAxis (javafx.scene.chart.NumberAxis)1 XYChart (javafx.scene.chart.XYChart)1 StringConverter (javafx.util.StringConverter)1