2016-09-27 43 views
16

我正在使用PChart创建线性图表。除了绘制的实际线条的质量之外,一切都很顺利。PChart线性图表图像质量

当然,抗锯齿是不是关闭,甚至明确打开。

下面是一个实际图像的例子,看起来相当丑陋的所有这些步骤。

enter image description here

有没有一种方法,使线画出的平滑,而不会干扰?

使用的代码:

public function linearTwoAxis($data, $fileName, $startColor = 0) 
{ 
    $pData = new \pData(); 

    $i = 0; 
    foreach ($data as $key => $row) 
    { 
     $serie = $this->translator->trans("pages.reportDefault.$key"); 
     $pData->addPoints($row, $serie); 
     $pData->setSerieOnAxis($serie, $i); 
     $pData->setSerieWeight($serie, 1); 
     $pData->setAxisName($i, $serie); 
     $pData->setPalette($serie, $this->colors[$startColor++]); 
     $pData->setAxisDisplay($i, AXIS_FORMAT_METRIC); 
     $i++; 
    } 
    $monthNames = array_keys($row); 

    $pData->setAxisPosition(1, AXIS_POSITION_RIGHT); 
    $pData->addPoints($monthNames, "Labels"); 
    $pData->setAbscissa("Labels"); 

    $pChart = new \pImage(750, 200, $pData); 

    $pChart->setFontProperties(array(
     "FontName" => $this->fonts_dir . "arial.ttf", 
     "FontSize" => 8) 
    ); 

    $pChart->setGraphArea(50, 10, 700, 150); 
    $pChart->Antialias = TRUE; 
    $pChart->drawScale(["Mode" => SCALE_MODE_START0]); 
    $pChart->drawLineChart(); 
    $pChart->drawLegend(325,180,array("Style"=>LEGEND_BOX,"Mode"=>LEGEND_HORIZONTAL, "BoxWidth"=>30,"Family"=>LEGEND_FAMILY_LINE,"Alpha" => 0)); 

    $pChart->render($this->target_dir . $fileName); 

    return $this->target_dirname . $fileName; 
} 
+0

http://pchart.sourceforge.net/documentation.php?topic=advexemple16。可能这会帮助你 –

+0

当你删除'$ pData-> setSerieWeight($ serie,1);'时,问题是否会持续存在? – simon

回答

4

如果没有别的帮助绘制图表大得多,然后缩小与ImageMagick的最终图像。这是最后的解决方案,它具有明显的额外计算成本。

这是一个示例行:

convert chart.png -resize 750×200 chart.jpg 

如果原始图像的两倍大(通过简单地加倍,你有两个维度在你的代码)一个调整这样就垮了四个像素为一体,平滑锯齿在五个级别(0%,25%,50%,75%,100%)。如果您将图像绘制得更大,则可以在绘制线条时关闭消除锯齿,因为调整大小会消除一切。

字体和可读性可能会成为一个问题,所以也许你要画两个图像:

  • 只是更大规模的线;
  • 其余的传说/统治者等原始的规模。

重新调整行图像的大小后,您必须将两个图像重叠为一个图像。这也可以通过ImageMagick完成。

+0

是的。鉴于报告中有30多张图片... –

+0

这不是调整大小的问题。这是生成初始图像的问题。 pChart需要很长时间才能生成更大的图像。 JFYI –

+0

这就是我的想法。但我不得不试一试:) – pid

3

如果删除setSerieWeight,它会产生更好的抗锯齿。例如。

<?php 

require_once "class/pDraw.class.php"; require_once "class/pImage.class.php"; require_once "class/pData.class.php"; 

$pData = new \pData(); 

$data = array(array(0,100),array(100,200),array(200,500)); 



    $i = 0; 
    foreach ($data as $key => $row) 
    { 
     $serie = 'test'; 
     $pData->addPoints($row, $serie); 
     $pData->setSerieOnAxis($serie, $i); 

     $pData->setAxisName($i, $serie); 
     $pData->setPalette($serie, array("R"=>74,"G"=>42,"B"=>112,"Alpha"=>100)); 
     $pData->setAxisDisplay($i, AXIS_FORMAT_METRIC); 
     $i++; 
    } 
    $monthNames = array_keys($row); 



    $pChart = new \pImage(750, 200, $pData); 

    $pChart->setFontProperties(array(
     "FontName" => "arial.ttf", 
     "FontSize" => 8) 
    ); 

    $pChart->setGraphArea(50, 10, 700, 150); 
    $pChart->Antialias = TRUE; 
    $pChart->drawScale(["Mode" => SCALE_MODE_START0]); 
    $pChart->drawLineChart(); 
    $pChart->drawLegend(325,180,array("Style"=>LEGEND_BOX,"Mode"=>LEGEND_HORIZONTAL, "BoxWidth"=>30,"Family"=>LEGEND_FAMILY_LINE,"Alpha" => 0)); 

    $pChart->render('test.png'); 

enter image description here