JFreeChart奇怪的渲染(无头RedHat) [英] JFreeChart strange rendering (headless RedHat)

查看:61
本文介绍了JFreeChart奇怪的渲染(无头RedHat)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将应用程序从Windows环境迁移到Redhat.该应用程序正在使用JfreeChart 1.0.6.它是一个Web应用程序,部署在运行在Open-JDK6上的Redhat无头环境中的tomcat 7中.

I am currently migrating an application from a windows environment to a Redhat one. This application is using JfreeChart 1.0.6. It is a web app deployed in a tomcat 7 on a Redhat headless environment running on a Open-JDK6).

我获得以下PNG.看起来像是手写的图表,所有内容都移到了图像的顶部.

I obtain the following PNG. It looks like handwrited chart and everything is shifted towards the top of the image.

有人已经遇到这样的问题并得到了解决吗?

Did someone already encounter such issue and got a fix?

请参阅下面的图表:

图片http://img194.imageshack.us/img194/4489/graph20120801105017. png

请参见下面的代码生成图表:

See below the piece of code generating the chart :

FacesContext facesContext = FacesContext.getCurrentInstance();
    ServletContext servlet = (ServletContext)facesContext.getExternalContext().getContext();
    HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String path = null;

    if (null != servlet.getRealPath("/"))
    {
        path = servlet.getRealPath("/");
    }
    else
    {
        path = servlet.getResource("/").getPath();
    }

    File stockageImg = new File(path+Constants.CHEMIN_GRAPH+CM50Util.dateHeureJour()+Constants.EXTENSION_GRAPH);

    ChartRenderingInfo info = new ChartRenderingInfo (new StandardEntityCollection());
    DefaultXYDataset dataset = new DefaultXYDataset();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    try 
    {
        dataset.addSeries("CM moyen Annuel", courbeRef);
        dataset.addSeries("CM non dépassé plus de 5% du temps", courbe95);

        //creation du graphique
        JFreeChart chart = ChartFactory.createXYLineChart(
             "Courbes de décroissance",
             "Distance en m\u00E8tre",
             "Champ",
             dataset,
             PlotOrientation.VERTICAL,
             true,
             false,
             false);

        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setRenderer(renderer);

        IntervalMarker intervalIncertitude = new IntervalMarker(Double.parseDouble(resultDistanceMin.replace(Constants.UNITE_DISTANCE, "")), Double.parseDouble(resultDistanceMax.replace(Constants.UNITE_DISTANCE, "")));
        intervalIncertitude.setPaint(new Color(222, 222, 255, 128));
        plot.addDomainMarker(intervalIncertitude, Layer.BACKGROUND);

        Marker distanceTiers = new ValueMarker(Double.parseDouble(resultDistance.replace(Constants.UNITE_DISTANCE, "")));
        distanceTiers.setPaint(Color.BLACK);
        plot.addDomainMarker(distanceTiers);

        renderer.setSeriesPaint(0, Color.GREEN);
        renderer.setSeriesPaint(1, Color.BLUE);

        ChartUtilities.saveChartAsPNG(stockageImg, chart, 800, 400, info);

    } catch (Exception e) {
            log.error("erreur generation graphique ",e);
    }

推荐答案

我找到了问题的原因:

  • 我记录了JfreeChart使用的字体:是SansSerif.plain
  • 查看OpenJDK的fontconfig.properties文件,我发现:

sansserif.plain.latin-1 = DejaVu LGC Sans

sansserif.plain.latin-1=DejaVu LGC Sans

文件名.DejaVu_LGC_Sans =/usr/share/fonts/dejavu-lgc/DejaVuLGCSans.ttf

filename.DejaVu_LGC_Sans=/usr/share/fonts/dejavu-lgc/DejaVuLGCSans.ttf

我没有在计算机上安装此字体,所以我安装了它,并且一切正常.

I didnt have this font installed on my machine, so I installed it and it went fine.

这篇关于JFreeChart奇怪的渲染(无头RedHat)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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