首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JpGraph分段背景色

问JpGraph分段背景色
EN

Stack Overflow用户
提问于 2012-11-05 10:58:23
回答 2查看 3.5K关注 0票数 1

我在PHP中使用JpGraph。我可以为大多数图表设置背景色

$graph->SetBackgroundGradient($bgcolor, $bgcolor, GRAD_HOR, BGRAD_MARGIN);

但是如何设置饼图的背景色呢?

这是最强大的PHP驱动图表,但仍然没有$graph->SetBackgroundColor($bgcolor)函数。

Br

EN

回答 2

Stack Overflow用户

发布于 2012-11-10 06:47:58

你看过SetMarginColor()还是SetColor()

SETMARGINCOLOR

票数 2
EN

Stack Overflow用户

发布于 2015-04-30 14:08:23

代码语言:javascript
复制
<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');
require_once ('jpgraph/jpgraph_pie3d.php');

// Some data
$data = array(
    array(80,18,15,17),
    array(35,28,6,34),
    array(10,28,10,5),
    array(22,22,10,17));

$piepos = array(0.2,0.4,0.65,0.28,0.25,0.75,0.8,0.75);
$titles = array('USA','Sweden','South America','Australia');

$n = count($piepos)/2;

// A new graph
$graph = new PieGraph(550,400,'auto');

// Specify margins since we put the image in the plot area
$graph->SetMargin(1,1,40,1);
$graph->SetMarginColor('navy');
$graph->SetShadow(false);

// Setup background
$graph->SetBackgroundImage('worldmap1.jpg',BGIMG_FILLPLOT);

// Setup title
$graph->title->Set("Pie plots with background image");
$graph->title->SetFont(FF_ARIAL,FS_BOLD,20);
$graph->title->SetColor('white');

$p = array();
// Create the plots
for( $i=0; $i < $n; ++$i ) {
    $d = "data$i";
    $p[] = new PiePlot3D($data[$i]);
}

// Position the four pies
for( $i=0; $i < $n; ++$i ) {
    $p[$i]->SetCenter($piepos[2*$i],$piepos[2*$i+1]);
}

// Set the titles
for( $i=0; $i < $n; ++$i ) {
    $p[$i]->title->Set($titles[$i]);
    $p[$i]->title->SetColor('white');
    $p[$i]->title->SetFont(FF_ARIAL,FS_BOLD,12);
}

// Label font and color setup
for( $i=0; $i < $n; ++$i ) {
    $p[$i]->value->SetFont(FF_ARIAL,FS_BOLD);
    $p[$i]->value->SetColor('white');
}

// Show the percetages for each slice
for( $i=0; $i < $n; ++$i ) {
    $p[$i]->value->Show();
}

// Label format
for( $i=0; $i < $n; ++$i ) {
    $p[$i]->value->SetFormat("%01.1f%%");
}

// Size of pie in fraction of the width of the graph
for( $i=0; $i < $n; ++$i ) {
    $p[$i]->SetSize(0.15);
}

// Format the border around each slice


for( $i=0; $i < $n; ++$i ) {
    $p[$i]->SetEdge(false);
    $p[$i]->ExplodeSlice(1);
}

// Use one legend for the whole graph
$p[0]->SetLegends(array("May","June","July","Aug"));
$graph->legend->Pos(0.05,0.35);
$graph->legend->SetShadow(false);

for( $i=0; $i < $n; ++$i ) {
    $graph->Add($p[$i]);
}

$graph->Stroke();
?>

参考资料:http://jpgraph.net/download/manuals/chunkhtml/ch16.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13230695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档