knowm / XChart

XChart is a light-weight Java library for plotting data.
http://knowm.org/open-source/xchart
Apache License 2.0
1.49k stars 397 forks source link

Legend is invisible after defining custom font #286

Closed DRSchlaubi closed 5 years ago

DRSchlaubi commented 5 years ago

I tried to create a pie chart with the ProductSans font

 Font font = Font.createFont(Font.PLAIN, new File("fonts/", "Product Sans Regular.ttf"));
        styler.setChartBackgroundColor(Colors.FULL_WHITE)
                .setLegendBackgroundColor(Colors.NOT_QUITE_BLACK)
                .setPlotBackgroundColor(Colors.BLURPLE)
                .setAnnotationsFont(font)
                .setLegendFont(font)
                .setToolTipFont(font)
                .setChartFontColor(Color.MAGENTA)
        ;

The Chart got generated like this

public PieChart(String heading, PieTile[] pieTiles) throws IOException, FontFormatException {
        this.heading = heading;
        this.chart = createChart();
        for (PieTile pieTile : pieTiles) {
            chart.addSeries(pieTile.getTile(), pieTile.getPercentage());
        }
        style(chart.getStyler());
    }

but unfortunately the legend font is completly invisible

timmolter commented 5 years ago

I never tried adding a font like that before, so I cannot say what they issue is. Does loading a font like that work in other instances like adding it to a JPanel?

DRSchlaubi commented 5 years ago

Fixed it because you need to set a font size otherwise the fint size is 1 and you cant see it