JpGraph饼图切片颜色不起作用

发布于 2024-10-27 20:24:22 字数 941 浏览 1 评论 0 原文

我在 php 中使用了 JpGraph。一切正常,但切片 ($p1->SetSliceColors($color);) 颜色不起作用。它一直是默认颜色。 这是我使用的代码。请帮我 :

    $data    = array('40','50', '10');
    $Legends = array('Loss','Win',  'Draw');
    $labels  = array("Loss\n(%.1f%%)","Win\n(%.1f%%)","Draw\n(%.1f%%)");
    $color   = array('red','red','red');
    $graph   = new PieGraph(550,350);
    $graph->SetShadow();

    $p1 = new PiePlot3D($data);
    $p1->ExplodeSlice(1);
    $p1->SetCenter(0.55);
    $p1->SetLegends($Legends);
    $graph->legend->Pos(0.5,0.1);


    $p1->SetTheme("earth");
    $p1->SetSliceColors($color);

    // Setup the labels to be displayed
    $p1->SetLabels($labels);
    $p1->SetLabelPos(1);
    $p1->SetLabelType(PIE_VALUE_PER);
    $p1->value->Show();
    $p1->value->SetFont(FF_FONT1,FS_NORMAL,9);
    $p1->value->SetColor('navy');

    $graph->Add($p1);
    $graph->Stroke();

I used a JpGraph in php. Everything ok but slice ($p1->SetSliceColors($color);) color not work. It all time default color.
Here is my used code. Please help me :

    $data    = array('40','50', '10');
    $Legends = array('Loss','Win',  'Draw');
    $labels  = array("Loss\n(%.1f%%)","Win\n(%.1f%%)","Draw\n(%.1f%%)");
    $color   = array('red','red','red');
    $graph   = new PieGraph(550,350);
    $graph->SetShadow();

    $p1 = new PiePlot3D($data);
    $p1->ExplodeSlice(1);
    $p1->SetCenter(0.55);
    $p1->SetLegends($Legends);
    $graph->legend->Pos(0.5,0.1);


    $p1->SetTheme("earth");
    $p1->SetSliceColors($color);

    // Setup the labels to be displayed
    $p1->SetLabels($labels);
    $p1->SetLabelPos(1);
    $p1->SetLabelType(PIE_VALUE_PER);
    $p1->value->Show();
    $p1->value->SetFont(FF_FONT1,FS_NORMAL,9);
    $p1->value->SetColor('navy');

    $graph->Add($p1);
    $graph->Stroke();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

咽泪装欢 2024-11-03 20:24:22

我也有同样的问题。在设置颜色之前调用Add方法:

$p1 = new PiePlot3D($data);
$graph->Add($p1);

更改折线图/条形图的显示设置

I had the same problem. Call the Add method before setting colors:

$p1 = new PiePlot3D($data);
$graph->Add($p1);

Changing the display settings of line/bar graphs

梅倚清风 2024-11-03 20:24:22

尝试

 $graph   = new PieGraph(550,350);
 $graph->ClearTheme();

忽略

 $p1->SetTheme("earth");

SetSliceColors 对我有用。

try

 $graph   = new PieGraph(550,350);
 $graph->ClearTheme();

Leave out

 $p1->SetTheme("earth");

SetSliceColors worked for me.

终陌 2024-11-03 20:24:22

您可以使用这行代码:
选择您要选择的主题,有几个选项

    $theme_class = new VividTheme;
    $graph = new PieGraph(1000,300);//create the graph
    $graph->ClearTheme();//clean
    $graph->SetTheme($theme_class);//set the theme 

现在您可以看到结果,您可以在这里看到不同的主题:

https://jpgraph.net/download/manuals/chunkhtml/ch28.html

模板的屏幕截图

其他选项是干净的主题,像这样

    $graph = new PieGraph(1000,300);//create the graph
    $graph->ClearTheme();//clean the theme
    $colors = array('#336699', '#FF0000', '#00FF00', '#0000FF', '#FFFF00');//put color the colors that you want
    $p1->SetSliceColors($colors);///set the colors

You can use this line of code:
Select the theme that you want to select, there are several options

    $theme_class = new VividTheme;
    $graph = new PieGraph(1000,300);//create the graph
    $graph->ClearTheme();//clean
    $graph->SetTheme($theme_class);//set the theme 

Now you can see the result, you can see the different themes here:

https://jpgraph.net/download/manuals/chunkhtml/ch28.html

screen shoot of themplates

Other option is clean the theme, something like this

    $graph = new PieGraph(1000,300);//create the graph
    $graph->ClearTheme();//clean the theme
    $colors = array('#336699', '#FF0000', '#00FF00', '#0000FF', '#FFFF00');//put color the colors that you want
    $p1->SetSliceColors($colors);///set the colors
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文