你是要动态生成image吧,把页面编码设置成GBK试试。
猜的。如果你能贴多谢代码可能会好些。

解决方案 »

  1.   

    public void graphicsPie() {
        try {
          int width = 600;
          int height = 500;      ChartGraphics chartGraphics = new ChartGraphics();      chartGraphics.image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);      Graphics g = chartGraphics.image.getGraphics();      Graphics2D g2d = (Graphics2D) g;      g.setColor(new Color(236, 233, 216));
          g.fillRect(0, 0, width, height);
          g.setColor(Color.white);
          g.fillRect(11, 35, width - 21, height - 47);
          g.setColor(Color.white);
          g.fillRect(10, 35, width - 20, height - 46);      g.setColor(Color.black);
          g.setFont(new Font("font", Font.PLAIN, 22));
          g.drawString("Info", 15, 25);
          /////////// From Here ,have some difference ////      int totalsales = 0;
          int book_sales[] = new int[5];
          for (int i = 0; i < book_sales.length; i++) {
            book_sales[i] = 1 + (int) (Math.random() * 100);
            totalsales += book_sales[i];
          }
          String book_title[] = {"python", "java", "c#", "peal", "php"};
          Color color[] = new Color[5];
          color[0] = new Color(99, 99, 0);
          color[1] = new Color(255, 169, 66);
          color[2] = new Color(33, 255, 66);
          color[3] = new Color(33, 0, 255);
          color[4] = new Color(255, 0, 66);      g.setFont(new Font("font0", Font.BOLD, 30));  
         String teststr = "这是测试程序";
         teststr = new String(teststr.getBytes("8859_1"), "GBK");     g.drawString(teststr, 50, 505);     g.setFont(new Font("sansserif", Font.BOLD, 12));
          g.drawString("SaleType", 400, 125);
          g.drawString("SaleNumber", 475, 125);
          g.drawString("Salepercent", 535, 125);
          g.setColor(Color.blue);
          g.drawRect(395,95,190,300);      int ArcStartAngle = 30;
          int ArcEndAngle = 0;
          float scale;
          DecimalFormat twoDigits = new DecimalFormat("0.00");      // *******************
          for (int i = 0; i < book_title.length; i++) {
            ArcEndAngle = (int) (book_sales[i] * 360/ (float)totalsales + 0.5);
            scale = (float)book_sales[i] / totalsales * 100;        g.setColor(color[i]);
            if ( i < book_title.length - 1 ) {
              g.fillArc(15,95,350,300,ArcStartAngle,ArcEndAngle);
            }else {
              g.fillArc(30,93,350,300,ArcStartAngle,ArcEndAngle);
            }
             ArcStartAngle += ArcEndAngle;
             g.fillRect(400,155 + i * 50,12,12);
             g.setColor(Color.black);          g.drawString(book_title[i], 420, 167 + i * 50);
              g.drawString("" + book_sales[i], 490, 167 + i * 50);
              g.drawString("" + twoDigits.format(scale) + "%", 540, 167 + i * 50);
          }      g.dispose();      chartGraphics.createImage(PicFile);    } catch(Exception e) {
          System.out.println("error = " + e.getMessage());
        }
      }
      

  2.   

    问题又来了,      g.setFont(new Font("宋体", Font.BOLD, 30));
         g.drawString("统计分析", 50, 505);这段代码在windows 下编译并能正确执行,中文也是正确的。但假如在中文系统下编译好 class 后,放到 unix 的web服务器下执行,中文就又变成方框了. 是 unix 没有这字体,那该怎么做呢?
      

  3.   

    那你可能要认真设置unix上java环境的
    font.properties文件里的相关配置,
    设置到相应的字体。