// create a bar graph $graph = new Graph(400,300); $graph->SetScale("textlin"); // set colors for bars $barplot = new BarPlot(array(10,20,30)); $barplot->SetFillColor('#00ff00'); $barplot->SetWidth(0.5); $graph->Add($barplot); // display the graph $graph->Stroke();
// create a pie chart $myData = new pData(); $myData->addPoints(array(20,30,45), "data"); $myData->setSerieDescription("data", "Data"); $myData->setAbscissa("Data"); // set colors for slices $pChart = new pChart(500,250); $pChart->setDataSet($myData); $pChart->setGraphArea(50,30,450,200); $pChart->drawPieLegend(10,10,$myData->getSerieDescription()); $pChart->drawPie3D(250,125,array("DrawLabels"=>TRUE,"DataGapAngle"=>10,"DataGapRadius"=>6,"WriteValues"=>TRUE,"Radius"=>100,"ValuePosition"=>PIE_VALUE_INSIDE,"ValuePadding"=>10)); // display the chart $pChart->render();In this example, the drawPie3D method from the pChart library is used to create a 3D pie chart with labeled slices. The SetColor method is not explicitly used, but the library automatically assigns colors to each slice based on a default color palette. Both examples demonstrate how setting colors can enhance the appearance of graphs and make them more visually appealing for data analysis.