eu.hansolo.tilesfx.chart.ChartData Java Examples

The following examples show how to use eu.hansolo.tilesfx.chart.ChartData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarChartItem.java    From tilesfx with Apache License 2.0 7 votes vote down vote up
public BarChartItem(final String NAME, final double VALUE, final Instant TIMESTAMP, final Duration DURATION, final Color COLOR) {
    nameColor          = new ObjectPropertyBase<Color>(Tile.FOREGROUND) {
        @Override protected void invalidated() { nameText.setFill(get()); }
        @Override public Object getBean() { return BarChartItem.this; }
        @Override public String getName() { return "nameColor"; }
    };
    valueColor         = new ObjectPropertyBase<Color>(Tile.FOREGROUND) {
        @Override protected void invalidated() {  valueText.setFill(get()); }
        @Override public Object getBean() { return BarChartItem.this; }
        @Override public String getName() { return "valueColor"; }
    };
    barBackgroundColor = new ObjectPropertyBase<Color>(Color.rgb(72, 72, 72)) {
        @Override protected void invalidated() { barBackground.setFill(get()); }
        @Override public Object getBean() { return BarChartItem.this; }
        @Override public String getName() { return "barBackgroundColor"; }
    };
    formatString       = "%.0f";
    locale             = Locale.US;
    maxValue           = 100;
    chartData          = new ChartData(NAME, VALUE, TIMESTAMP, DURATION, COLOR);
    stepSize           = PREFERRED_WIDTH * 0.85 / maxValue;
    parentWidth        = 250;
    parentHeight       = 250;
    initGraphics();
    registerListeners();
}
 
Example #2
Source File: TimelineTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void handleMouseEvents(final MouseEvent e) {
    EventType type = e.getEventType();
    Circle    dot  = (Circle) e.getSource();
    ChartData data = dots.entrySet().stream().filter(entry -> entry.getValue().equals(dot)).map(entry -> entry.getKey()).findAny().orElse(null);
    if (MouseEvent.MOUSE_ENTERED.equals(type)) {
        if (null != data) {
            dotTooltip.setX(e.getScreenX());
            dotTooltip.setY(e.getScreenY());
            LocalDateTime localDateTime = LocalDateTime.ofInstant(data.getTimestamp(), tile.getZoneId());
            dotTooltip.setText(String.join("\n", DTF.format(localDateTime), String.format(tile.getLocale(), String.join(" ", formatString, tile.getUnit()), data.getValue())));
            dotTooltip.show(tile.getScene().getWindow());
        }
    } else if (MouseEvent.MOUSE_EXITED.equals(type)) {
        dotTooltip.hide();
    }
}
 
Example #3
Source File: MatrixTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void updateMatrixWithChartData() {
    List<ChartData> dataList = tile.getChartData();
    int             cols     = dataList.size();
    int             rows     = matrix.getRows();
    double          factor   = rows / tile.getRange();
    Color           offColor = matrix.getPixelOffColor();

    matrix.setAllPixelsOff();
    for (int y = rows ; y >= 0 ; y--) {
        for (int x = 0 ; x < cols; x++) {
            int noOfActivePixels = Helper.roundDoubleToInt((maxValue - dataList.get(x).getValue()) * factor);
            matrix.setPixel(x, y, noOfActivePixels <= y ? dataList.get(x).getFillColor() : offColor);
        }
    }
    matrix.drawMatrix();
}
 
Example #4
Source File: DonutChartTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void drawLegend() {
    List<ChartData> dataList     = tile.getChartData();
    double          canvasWidth  = legendCanvas.getWidth();
    double          canvasHeight = legendCanvas.getHeight();
    int             noOfItems    = dataList.size();
    Color           textColor    = tile.getTextColor();
    double          stepSize     = canvasHeight * 0.9 / (noOfItems + 1);

    legendCtx.clearRect(0, 0, canvasWidth, canvasHeight);
    legendCtx.setTextAlign(TextAlignment.LEFT);
    legendCtx.setTextBaseline(VPos.CENTER);
    legendCtx.setFont(Fonts.latoRegular(canvasHeight * 0.05));

    for (int i = 0 ; i < noOfItems ; i++) {
        ChartData data = dataList.get(i);

        legendCtx.setFill(data.getFillColor());
        legendCtx.fillOval(0, (i + 1) * stepSize, size * 0.0375, size * 0.0375);
        legendCtx.setFill(textColor);
        legendCtx.fillText(data.getName(), size * 0.05, (i + 1) * stepSize + canvasHeight * 0.025);
    }
}
 
Example #5
Source File: ClusterMonitorTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
public ChartItem(final ChartData CHART_DATA, final CtxBounds CONTENT_BOUNDS, final String FORMAT_STRING) {
    chartData         = CHART_DATA;
    contentBounds     = CONTENT_BOUNDS;
    title             = new Label(chartData.getName());
    value             = new Label(String.format(Locale.US, FORMAT_STRING, chartData.getValue()));
    scale             = new Rectangle(0, 0);
    bar               = new Rectangle(0, 0);
    formatString      = FORMAT_STRING;
    step              = PREF_WIDTH / (CHART_DATA.getMaxValue() - CHART_DATA.getMinValue());
    compressed        = false;
    chartDataListener = e -> {
        switch(e.getType()) {
            case UPDATE  : update(); break;
            case FINISHED: update(); break;
        }
    };
    initGraphics();
    registerListeners();
}
 
Example #6
Source File: RadialPercentageTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
@Override protected void handleEvents(final String EVENT_TYPE) {
    super.handleEvents(EVENT_TYPE);
    if ("RECALC".equals(EVENT_TYPE)) {
        referenceValue = tile.getReferenceValue() < maxValue ? maxValue : tile.getReferenceValue();
        angleStep      = ANGLE_RANGE / range;
        sum            = dataList.stream().mapToDouble(ChartData::getValue).sum();
        sections       = tile.getSections();
        redraw();
        setBar(tile.getCurrentValue());
    } else if ("VISIBILITY".equals(EVENT_TYPE)) {
        enableNode(titleText, !tile.getTitle().isEmpty());
        enableNode(text, tile.isTextVisible());
        enableNode(unitText, !tile.getUnit().isEmpty());
        enableNode(descriptionText, tile.isValueVisible());
    }
}
 
Example #7
Source File: CalendarTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void checkClick(final MouseEvent EVENT) {
    Label  selectedLabel = ((Label) EVENT.getSource());
    String selectedText  = selectedLabel.getText();
    if (null == selectedText ||
        selectedText.isEmpty() ||
        !Character.isDigit(selectedText.charAt(0))) { return; }
    if (selectedLabel.getBorder() != null && selectedLabel.getBorder().equals(weekBorder)) { return; }
    int selectedNo = Integer.parseInt(selectedText);
    if (selectedNo > 31) { return; }

    List<ChartData>     dataList          = tile.getChartData();
    ZonedDateTime       time              = tile.getTime();
    LocalDate           selectedDate      = LocalDate.of(time.getYear(), time.getMonth(), selectedNo);
    Optional<ChartData> selectedChartData = dataList.stream().filter(data -> data.getTimestampAsLocalDate().isEqual(selectedDate)).findAny();

    if (selectedChartData.isPresent()) { tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, selectedChartData.get())); }
}
 
Example #8
Source File: SmoothAreaChartTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void handleData() {
    selectorTooltip.hide();
    selector.setVisible(false);
    List<ChartData> data = tile.getChartData();
    if (null == data || data.isEmpty() || data.size() < 2) { return; }

    if (!strokePath.isVisible() && !fillPath.isVisible()) {
        fillPath.setVisible(true);
        strokePath.setVisible(true);
        Helper.enableNode(dataPointGroup, tile.getDataPointsVisible());
    }

    Optional<ChartData> lastDataEntry = data.stream().reduce((first, second) -> second);
    if (lastDataEntry.isPresent()) {
        if (tile.getCustomDecimalFormatEnabled()) {
            valueText.setText(decimalFormat.format(lastDataEntry.get().getValue()));
        } else {
            valueText.setText(String.format(locale, formatString, lastDataEntry.get().getValue()));
        }
        tile.setValue(lastDataEntry.get().getValue());
        resizeDynamicText();
    }
    dataSize  = data.size();
    maxValue  = data.stream().max(Comparator.comparing(c -> c.getValue())).get().getValue();
    hStepSize = width / (dataSize - 1);
    vStepSize = (height * 0.5) / maxValue;

    points.clear();
    for (int i = 0 ; i < dataSize ; i++) {
        points.add(new Point((i) * hStepSize, height - data.get(i).getValue() * vStepSize));
    }
    drawChart(points);
}
 
Example #9
Source File: CycleStepTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public ChartItem(final ChartData chartData, final double sum) {
    this.chartData = chartData;
    this.sum       = sum;
    this.factorX   = 0;
    initGraphics();
    registerListeners();
}
 
Example #10
Source File: ClusterMonitorTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void updateChart() {
    int noOfItems = dataItemMap.size();
    if (noOfItems == 0) return;
    for (int i = 0 ; i < noOfItems ; i++) {
        ChartData item = dataItemMap.keySet().iterator().next();
        dataItemMap.get(item).update();

        if (i > 1) { break; }
    }
}
 
Example #11
Source File: ClusterMonitorTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    updateHandler    = e -> {
        switch(e.getType()) {
            case UPDATE  : updateChart(); break;
            case FINISHED: updateChart(); break;
        }
    };
    paneSizeListener = e -> updateChart();
    dataItemMap      = new HashMap<>();

    chartPane = new VBox();

    Collections.sort(tile.getChartData(), Comparator.comparing(ChartData::getName));
    tile.getChartData().forEach(data -> {
        data.addChartDataEventListener(updateHandler);
        dataItemMap.put(data, new ChartItem(data, contentBounds, data.getFormatString()));
        chartPane.getChildren().add(dataItemMap.get(data));
    });

    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    text = new Text(tile.getText());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());

    SVGPath svgPath = tile.getSVGPath();
    if (null != svgPath) {
        svgPathPressedHandler = e -> tile.fireTileEvent(SVG_PRESSED_EVENT);
        graphicRegion = new Region();
        graphicRegion.setShape(svgPath);
        getPane().getChildren().addAll(titleText, text, chartPane, graphicRegion);
    } else {
        getPane().getChildren().addAll(titleText, text, chartPane);
    }
}
 
Example #12
Source File: WorldMapTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void registerListeners() {
    super.registerListeners();
    countryPaths.forEach((name , pathList) -> {
        Country country = Country.valueOf(name);
        EventHandler<MouseEvent> clickHandler = e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, new ChartData(country.getName(), country.getValue(), country.getColor())));
        pathList.forEach(path -> {
            handlerMap.put(path, clickHandler);
            path.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
        });
    });
    tile.getPoiList().addListener(poiListener);
    tile.getChartData().addListener(chartDataListener);
}
 
Example #13
Source File: TimelineTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void analyse(final List<ChartData> clampedDataList) {
    double noOfPointsInTimePeriod = clampedDataList.size();
    percentageInSections.entrySet().forEach(entry -> {
        double noOfPointsInSection = clampedDataList.stream().filter(chartData -> entry.getKey().contains(chartData.getValue())).mapToDouble(ChartData::getValue).count();
        entry.getValue().setText(String.format(tile.getLocale(), "%.0f%%", ((noOfPointsInSection / noOfPointsInTimePeriod * 100))));
    });
}
 
Example #14
Source File: TimelineTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void registerListeners() {
    super.registerListeners();
    tile.timePeriodProperty().addListener(periodListener);
    tile.getChartData().addListener((ListChangeListener<ChartData>) c -> {
        while(c.next()) {
            if (c.wasAdded()) {
                c.getAddedSubList().forEach(chartData -> addData(chartData));
            }
        }
        Set<ChartData> dataSet = tile.getChartData().stream().filter(data -> !dataList.contains(data)).collect(Collectors.toSet());
        Platform.runLater(() -> tile.removeChartData(new ArrayList<>(dataSet)));
    });
    tile.getSections().addListener((ListChangeListener<Section>) c -> {
        while(c.next()) {
            if (c.wasAdded()) {
                c.getAddedSubList().forEach(section -> {
                    Rectangle sectionRect = new Rectangle();
                    sectionRect.setMouseTransparent(true);
                    sections.put(section, sectionRect);
                });
            } else if (c.wasRemoved()) {
                c.getRemoved().forEach(section -> sections.remove(section));
            }
        }
        sectionGroup.getChildren().setAll(sections.values());
        resize();
    });
}
 
Example #15
Source File: LeaderBoardItem.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public LeaderBoardItem(final String NAME, final double VALUE, final Instant TIMESTAMP, final Duration DURATION) {
    chartData            = new ChartData(NAME, VALUE, TIMESTAMP, DURATION);
    nameColor            = new ObjectPropertyBase<>(Tile.FOREGROUND) {
        @Override protected void invalidated() { nameText.setFill(get()); }
        @Override public Object getBean() { return LeaderBoardItem.this; }
        @Override public String getName() { return "nameColor"; }
    };
    valueColor           = new ObjectPropertyBase<>(Tile.FOREGROUND) {
        @Override protected void invalidated() {  valueText.setFill(get()); }
        @Override public Object getBean() { return LeaderBoardItem.this; }
        @Override public String getName() { return "valueColor"; }
    };
    separatorColor       = new ObjectPropertyBase<>(Color.rgb(72, 72, 72)) {
        @Override protected void invalidated() { separator.setStroke(get()); }
        @Override public Object getBean() { return LeaderBoardItem.this; }
        @Override public String getName() { return "separatorColor"; }
    };
    itemSortingTopic     = ItemSortingTopic.VALUE;
    formatString         = "%.0f";
    durationFormatString = "%d:%02d:%02d";
    timestampFormatter   = DateTimeFormatter.ofPattern("dd.MM.yyyy hh:mm:ss");
    locale               = Locale.US;
    index                = 1024;
    lastIndex            = 1024;
    parentWidth          = 250;
    parentHeight         = 250;

    initGraphics();
    registerListeners();
}
 
Example #16
Source File: SunburstChartTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void registerListeners() {
    super.registerListeners();

    TreeNode<ChartData> tree = tile.getSunburstChart().getTreeNode();
    if (null == tree) { return; }
    tree.setOnTreeNodeEvent(e -> {
        EventType type = e.getType();
        if (EventType.NODE_SELECTED == type) {
            TreeNode<ChartData> segment = e.getSource();
            tile.fireTileEvent(new TileEvent(TileEvent.EventType.SELECTED_CHART_DATA, segment.getItem()));
        }
    });
}
 
Example #17
Source File: Statistics.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final double getChartDataAverage(final List<ChartData> DATA) {
    return getAverage(DATA.stream().map(ChartData::getValue).collect(Collectors.toList()));
}
 
Example #18
Source File: Statistics.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final double getChartDataMean(final List<ChartData> DATA) {
    return getMean(DATA.stream().map(ChartData::getValue).collect(Collectors.toList()));
}
 
Example #19
Source File: Statistics.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final double getChartDataStdDev(final List<ChartData> DATA) {
    return getStdDev(DATA.stream().map(ChartData::getValue).collect(Collectors.toList()));
}
 
Example #20
Source File: Statistics.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final double getChartDataMedian(final List<ChartData> DATA) {
    return getMedian(DATA.stream().map(ChartData::getValue).collect(Collectors.toList()));
}
 
Example #21
Source File: Statistics.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final double getChartDataVariance(final List<ChartData> DATA) {
    return getVariance(DATA.stream().map(ChartData::getValue).collect(Collectors.toList()));
}
 
Example #22
Source File: ChartDataEvent.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public ChartDataEvent(final EventType TYPE, final ChartData DATA) {
    type = TYPE;
    data = DATA;
}
 
Example #23
Source File: Statistics.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final double getChartDataMin(final List<ChartData> DATA) {
    return getMin(DATA.stream().map(ChartData::getValue).collect(Collectors.toList()));
}
 
Example #24
Source File: Statistics.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final double getChartDataMax(final List<ChartData> DATA) {
    return getMax(DATA.stream().map(ChartData::getValue).collect(Collectors.toList()));
}
 
Example #25
Source File: TileEvent.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public TileEvent(final EventType EVENT_TYPE, final ChartData DATA) {
    this.EVENT_TYPE = EVENT_TYPE;
    this.DATA       = DATA;
}
 
Example #26
Source File: TileBuilder.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public final B chartData(final List<ChartData> DATA) {
    properties.put("chartDataList", new SimpleObjectProperty(DATA));
    return (B)this;
}
 
Example #27
Source File: TileBuilder.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public final B chartData(final ChartData... DATA) {
    properties.put("chartDataArray", new SimpleObjectProperty(DATA));
    return (B)this;
}
 
Example #28
Source File: RadialChartTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
private void drawChart() {
    double          canvasSize     = chartCanvas.getWidth();
    double          radius         = canvasSize * 0.5;
    double          innerSpacer    = radius * 0.18;
    double          barWidth       = (radius - innerSpacer) / tile.getChartData().size();
    //List<RadialChartData> sortedDataList = tile.getChartData().stream().sorted(Comparator.comparingDouble(RadialChartData::getValue)).collect(Collectors.toList());
    List<ChartData> dataList       = tile.getChartData();
    int             noOfItems      = dataList.size();
    double          max            = noOfItems == 0 ? 0 : dataList.stream().max(Comparator.comparingDouble(ChartData::getValue)).get().getValue();

    double          nameX          = radius * 0.975;
    double          nameWidth      = radius * 0.95;
    double          valueY         = radius * 0.94;
    double          valueWidth     = barWidth * 0.9;
    Color           bkgColor       = Color.color(tile.getTextColor().getRed(), tile.getTextColor().getGreen(), tile.getTextColor().getBlue(), 0.15);

    chartCtx.clearRect(0, 0, canvasSize, canvasSize);
    chartCtx.setLineCap(StrokeLineCap.BUTT);
    chartCtx.setFill(tile.getTextColor());
    chartCtx.setTextAlign(TextAlignment.RIGHT);
    chartCtx.setTextBaseline(VPos.CENTER);
    chartCtx.setFont(Fonts.latoRegular(barWidth * 0.5));

    chartCtx.setStroke(bkgColor);
    chartCtx.setLineWidth(1);
    chartCtx.strokeLine(radius, 0, radius, radius - barWidth * 0.875);
    chartCtx.strokeLine(0, radius, radius - barWidth * 0.875, radius);
    chartCtx.strokeArc(noOfItems * barWidth, noOfItems * barWidth, canvasSize - (2 * noOfItems * barWidth), canvasSize - (2 * noOfItems * barWidth), 90, -270, ArcType.OPEN);

    for (int i = 0 ; i < noOfItems ; i++) {
        ChartData data  = dataList.get(i);
        double    value = clamp(0, Double.MAX_VALUE, data.getValue());
        double    bkgXY = i * barWidth;
        double    bkgWH = canvasSize - (2 * i * barWidth);
        double    barXY = barWidth * 0.5 + i * barWidth;
        double    barWH = canvasSize - barWidth - (2 * i * barWidth);
        double    angle = value / max * 270.0;

        // Background
        chartCtx.setLineWidth(1);
        chartCtx.setStroke(bkgColor);
        chartCtx.strokeArc(bkgXY, bkgXY, bkgWH, bkgWH, 90, -270, ArcType.OPEN);

        // DataBar
        chartCtx.setLineWidth(barWidth);
        chartCtx.setStroke(data.getFillColor());
        chartCtx.strokeArc(barXY, barXY, barWH, barWH, 90, -angle, ArcType.OPEN);

        // Name
        chartCtx.setTextAlign(TextAlignment.RIGHT);
        chartCtx.fillText(data.getName(), nameX, barXY, nameWidth);

        // Value
        chartCtx.setTextAlign(TextAlignment.CENTER);
        chartCtx.fillText(String.format(Locale.US, "%.0f", value), barXY, valueY, valueWidth);
    }
}
 
Example #29
Source File: DonutChartTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
private void drawChart() {
    List<ChartData> dataList;
    switch(tile.getItemSorting()) {
        case ASCENDING : dataList = tile.getChartData().stream().sorted(Comparator.comparingDouble(ChartData::getValue)).collect(Collectors.toList()); break;
        case DESCENDING: dataList = tile.getChartData().stream().sorted(Comparator.comparingDouble(ChartData::getValue).reversed()).collect(Collectors.toList()); break;
        case NONE      :
        default        : dataList = tile.getChartData(); break;
    }

    double          canvasSize     = chartCanvas.getWidth();
    int             noOfItems      = dataList.size();
    double          center         = canvasSize * 0.5;
    double          barWidth       = canvasSize * 0.09;
    double          sum            = dataList.stream().mapToDouble(ChartData::getValue).sum();
    double          stepSize       = 360.0 / sum;
    double          angle          = 0;
    double          startAngle     = 90;
    double          xy             = canvasSize * 0.15;
    double          wh             = canvasSize * 0.7;
    //Color           bkgColor       = tile.getBackgroundColor();
    Color           textColor      = tile.getTextColor();

    centerX        = xy + wh * 0.5;
    centerY        = xy + wh * 0.5;
    innerRadius    = canvasSize * 0.225;
    outerRadius    = canvasSize * 0.45;

    chartCtx.clearRect(0, 0, canvasSize, canvasSize);
    chartCtx.setLineCap(StrokeLineCap.BUTT);
    chartCtx.setFill(textColor);
    chartCtx.setTextBaseline(VPos.CENTER);
    chartCtx.setTextAlign(TextAlignment.CENTER);

    // Sum
    if (tile.isValueVisible()) {
        chartCtx.setFont(Fonts.latoRegular(canvasSize * 0.15));
        chartCtx.fillText(String.format(Locale.US, "%.0f", sum), center, center, canvasSize * 0.4);
    }

    chartCtx.setFont(Fonts.latoRegular(barWidth * 0.5));
    for (int i = 0 ; i < noOfItems ; i++) {
        ChartData data  = dataList.get(i);
        double    value = data.getValue();
        startAngle -= angle;
        angle = value * stepSize;

        // Segment
        chartCtx.setLineWidth(barWidth);
        chartCtx.setStroke(data.getFillColor());
        chartCtx.strokeArc(xy, xy, wh, wh, startAngle, -angle, ArcType.OPEN);

        double radValue = Math.toRadians(startAngle - (angle * 0.5));
        double cosValue = Math.cos(radValue);
        double sinValue = Math.sin(radValue);

        // Percentage
        double x = innerRadius * cosValue;
        double y = -innerRadius * sinValue;
        chartCtx.setFill(textColor);
        chartCtx.fillText(String.format(Locale.US, "%.0f%%", (value / sum * 100.0)), center + x, center + y, barWidth);

        // Value
        if (angle > 10) {
            x = outerRadius * cosValue;
            y = -outerRadius * sinValue;
            chartCtx.setFill(data.getTextColor());
            chartCtx.fillText(String.format(Locale.US, "%.0f", value), center + x, center + y, barWidth);
        }
    }
}
 
Example #30
Source File: BarChartItem.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public void setChartData(final ChartData DATA) {
    chartData = DATA;
    chartData.fireChartDataEvent(new ChartDataEvent(EventType.UPDATE, chartData));
}