Вопрос

I have created a graph using jpgraph - it works however due to the length of the labels on my x-axis some of text is being 'cut-off' an isn't visible. I have created a custom function to use the newline but even with this it still trims off a few characters on one of the labels on the chart.

Is there a method to actual define the actual length of the x-axis labels eg set a width in pixels? Thanks

        // Create the graph. These two calls are always required
    $graph = new Graph(1000,500,'auto');
    $graph->SetScale("textlin");

    //$theme_class="DefaultTheme";
    //$graph->SetTheme(new $theme_class());

    // set major and minor tick positions manually
    $graph->yaxis->SetTickPositions(array(0,1,2,3,4,5), array(0.5,1.5,2.5,3.5,4.5));
    $graph->SetBox(false);

    //$graph->ygrid->SetColor('gray');
    $graph->ygrid->SetFill(false);
    $graph->xaxis->SetLabelAngle(90); // 45 degrees angle
    $graph->xaxis->SetTickLabels($new_labels);
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);

    // Create the bar plots
    $b1plot = new BarPlot($data);

    // ...and add it to the graPH
    $graph->Add($b1plot);        

    $b1plot->SetColor("white");
    $b1plot->SetFillGradient("#4B0082","white",GRAD_LEFT_REFLECTION);
    $b1plot->SetWidth(45);
    $graph->title->Set("Bar Gradient(Left reflection)");

    // Display the graph
    $graph->Stroke();
Это было полезно?

Решение

Figured out (almost) Just in case anyone else needs help use the following:

$graph->xaxis->SetLabelAlign('right','center','right');

Другие советы

I don't think you can set the length of the labels. You will need to set the margins for the graph using either $graph->setMargin(a,b,c,d); or $graph->Set90AndMargin(a,b,c,d); for a rotated graph. a - left, b - right, c - top, d - bottom margin.

Look up the documentation on these functions it can be a little confusing with the rotated graph.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top