0

我正在尝试绘制调查结果,其中问题是多项选择。

例如。你会如何描述这个网站?格式:

option | number of times selected | percentage of users who selected that option

Informative     1   50%
All of the above    1   50%
Interesting     0   0%
Intelligent     0   0%
Cool    0   0%
Incredible  0   0%
Sleek   0   0%
Amazing

该图是一个条形图,其中每个条形代表其中一个选项,条形的高度取决于选择的次数。

然而,标签以 45 度角倾斜,几乎无法阅读!这是我的代码:

<?php
require_once ("includes/common.php");
require_once ("graph/mtChart.min.php");

// type must be specified
$type = $_GET['type'];

if($type == "surveys_report_MC_or_CB") {
    // PARAMS
    $surveyID   = $_GET['surveyID'];
    $questionID = $_GET['questionID'];
    // END PARAMS

    $question   = SurveyQuestions::getSingle($questionID);
    $answers    = SurveyAnswers::getAll($questionID);

    $options        = SurveyQuestionOptions::getAll($question[SurveyQuestions::surveyQuestionID]);
    $others         = SurveyAnswers::setOptionCounts($options, $answers);
    $printedOthers  = false;

    // set graph
    $values = array();
    $axisLabels = array();
    foreach($options as $option) {
        $values[$option[SurveyQuestionOptions::optionText]] = $option['count'];
        $axisLabels[] = $option[SurveyQuestionOptions::optionText];
    }

    $graphs = array();
    $graphs[0] = $values;

    $xName = "Option";
    $yName = "Number of Times Selected";
    $graphTitle = $question[SurveyQuestions::question];
    $series = array("Total");
    $showLegend = false;
    $tall = false;
}                   

drawGraph($graphs, $axisLabels, $xName, $yName, $graphTitle, $series, $showLegend, $tall);




function drawGraph($graphs, $axisLabels, $xName, $yName, $graphTitle, $series, $showLegend, $tall) {
        $Graph = ($tall) ? new mtChart(575,375) : new mtChart(575,275);

        // Dataset definition
        $avg = 0;
        $i = 0;
        foreach ($graphs as $key => $value) {
            $Graph->AddPoint($value,"series" . $key);
            $Graph->SetSerieName($series[$key],"series" . $key);

            // Get average
            $avg += array_sum($value);
            $size = sizeof($value);
            $i += $size;

            // Calculate x-axis tick interval
            $step = ceil($size / 25);
        }

        $Graph->AddPoint($axisLabels,"XLabel");
        $Graph->AddAllSeries();
        $Graph->RemoveSerie("XLabel");
        $Graph->SetAbsciseLabelSerie("XLabel");
        $Graph->SetXAxisName($xName);
        $Graph->SetYAxisName($yName);

        // Get from cache if it exists
        $Graph->enableCaching(NULL, 'graph/cache/');
        $Graph->GetFromCache();

        // Initialize the graph
        $Graph->setInterval($step);
        $Graph->setFontProperties("graph/tahoma.ttf",8);
        ($showLegend) ? $Graph->setGraphArea(45,30,475,200) : $Graph->setGraphArea(75,30,505,200);
        $Graph->drawGraphArea(255,255,255,TRUE);
        $Graph->drawScale(SCALE_START0,100,100,100,TRUE,55,1,TRUE);
        $Graph->drawGrid(4,TRUE,230,230,230,50);

        // Draw the 0 line
        $Graph->setFontProperties("graph/tahoma.ttf",6);
        $Graph->drawTreshold(0,143,55,72,TRUE,TRUE);

        // Draw the bar graph
        $Graph->drawBarGraph();

        // Draw average line
        $Graph->drawTreshold($avg/$i, 0, 0, 0, FALSE, FALSE, 5);     

        // Finish the graph
        $Graph->setFontProperties("graph/tahoma.ttf",8);
        if ($showLegend) {
            $Graph->drawLegend(482,30,255,255,255,255,255,255,100,100,100);
        }
        $Graph->setFontProperties("graph/tahoma.ttf",10);
        $Graph->drawTitle(0,22,$graphTitle,100,100,100,555);

        // Draw Graph
        $Graph->Stroke();
    }

这是我在页面上使用它的地方:

<div class="graph_container">
                            <img src="drawGraph.php?type=surveys_report_MC_or_CB&surveyID=<?php
                                echo $survey[Surveys::surveyID] ?>&questionID=<?php
                                echo $question[SurveyQuestions::surveyQuestionID] ?>" />

有没有我可以应用到图表上的设置,它可以使文本看起来更好,或者至少让我将角度设置为 90 度,以便人们在他们向左抬起头时可以阅读它?

顺便说一句,mtchart位于此处:http ://code.google.com/p/mtchart/ 和 pchart(原始,主要具有相同的代码)在这里:http ://pchart.sourceforge.net/documentation.php

4

1 回答 1

1

编辑以下绘制水平标签的行:

 $Graph->drawScale(SCALE_START0,100,100,100,TRUE,55,1,TRUE);
 //                                              ^^--- Edit this value

第六个参数 ( 55) 是书写文本的角度;0是水平的,90是垂直的,120是靠在自己身上的,等等。所以,如果你想要一些头部翘起,请将值设置为90

该方法的整个原型是:

void drawScale(int $ScaleMode = SCALE_NORMAL, 
               int $R = 150, int $G = 150, int $B = 150, 
               bool $DrawTicks = TRUE, int $Angle = 0, int $Decimals = 1, 
               bool $WithMargin = FALSE, bool $RightScale = FALSE)
于 2010-06-14T21:06:23.587 回答