用PDFbox绘制饼图 [英] Drawing pie chart with PDFbox

查看:183
本文介绍了用PDFbox绘制饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试着用PDFbox绘制饼图,但切片之间有白线,有人能帮我吗?是否有此选项?

附上我正在使用的绘制圆弧的代码:

while (start < stop) {
    List<Float> smallArc = PdfUtils.createSmallArc(a, b, radius, start, start + 
        2.0944 > stop ? stop : start + 2.0944);
    contentStream.saveGraphicsState();
    contentStream.setNonStrokingColor(components[0], components[1], 
        components[2]);
    contentStream.moveTo(smallArc.get(0), smallArc.get(1));
    contentStream.curveTo(smallArc.get(2), smallArc.get(3), smallArc.get(4), 
        smallArc.get(5), smallArc.get(6), smallArc.get(7));
    contentStream.fill();
    contentStream.restoreGraphicsState();
    start += 2.0944;
}


public static List<Float> createSmallArc(float x, float y, double r, double a1, double a2) {
    double a = (a2 - a1) / 2;
    double x4 = r * Math.cos(a);
    double y4 = r * Math.sin(a);
    double x1 = x4;
    double y1 = -y4;
    double q1 = x1 * x1 + y1 * y1;

    double q2 = q1 + x1 * x4 + y1 * y4;
    double k2 = 4 / 3d * (Math.sqrt(2 * q1 * q2) - q2) / (x1 * y4 - y1 * x4);
    double x2 = x1 - k2 * y1;
    double y2 = y1 + k2 * x1;
    double x3 = x2;
    double y3 = -y2;

    double ar = a + a1;
    double cos_ar = Math.cos(ar);
    double sin_ar = Math.sin(ar);

    List<Float> list = new ArrayList<Float>();
    list.add((float) (r * Math.cos(a1)) + x);
    list.add((float) -(r * Math.sin(a1)) + y);
    list.add((float) (x2 * cos_ar - y2 * sin_ar) + x);
    list.add((float) -(x2 * sin_ar + y2 * cos_ar) + y);
    list.add((float) (x3 * cos_ar - y3 * sin_ar) + x);
    list.add((float) -(x3 * sin_ar + y3 * cos_ar) + y);
    list.add((float) (r * Math.cos(a2)) + x);
    list.add((float) -(r * Math.sin(a2)) + y);
    return list;
}

结果附图:

谢谢

推荐答案

不使用fill(),而是使用fillAndStroke()方法并使用与setNonStrokingColor()相同的参数调用setStrokingColor()

这篇关于用PDFbox绘制饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆