JpGraph饼图切片颜色不起作用

问题描述 投票:0回答:4

我在 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();
pie-chart jpgraph
4个回答
13
投票

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

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

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


5
投票

尝试

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

省略

 $p1->SetTheme("earth");

SetSliceColors 对我有用。


0
投票

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

    $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

0
投票

将饼图添加到图表后尝试调用

SetSliceColors
方法,它将按预期工作:

    $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");

    // 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);
    $p1->SetSliceColors($color);
    $graph->Stroke();
© www.soinside.com 2019 - 2024. All rights reserved.