美文网首页
JpGraph 柱状图(bar)复杂 legend+tickLa

JpGraph 柱状图(bar)复杂 legend+tickLa

作者: sowork | 来源:发表于2018-12-21 15:42 被阅读5次
    成品图如下
            $d = [100, 20, 30, 40, 100, 50, 90, 90, 60, 200, 100, 20, 30, 40, 100, 50, 90, 90, 60, 200, 60, 80, 400]; // 数据和图显示的y轴数据不符
            $names = [ '面部表情识别能力', '情景表情识别能力',  '微表情识别', '情绪状态理解',  '自我控制能力' ,'合作性', '主张性' ,'责任感', '同伴能力', '社会技能', '情绪感知', '情绪运用', '情绪理解', '情绪管理', '胜任力', '逆境处理能力', '毅力', '自我效能感', '积极情感', '消极情感', '同感能力', '压力应激level1', '压力应激level2' ]; // x轴的tickLabel
            JpGraph::module('bar');  // 柱状图
            $c = ['#40699c', '#9e413e', '#7f9a48', '#695185', '#3c8da3', '#cc7b38', '#4177b7', '#b83a37', '#a1bf63', '#8064a2', '#4bacc6', '#f79544'];
    
            $graph = new \Graph(552, 353);
            $graph->SetScale('textlin');
    
            $iconv = [];
            foreach ($names as $k => $v) {
                $iconv[] = iconv('UTF-8', 'GB2312//IGNORE', $v);
            }
            $graph->xaxis->SetFont(FF_SIMSUN, FS_NORMAL, 9);
            $graph->xaxis->SetTickLabels($iconv);
    
            $graph->SetMargin(40,100,20,110);
            $graph->xaxis->SetLabelAlign('center','top');
            $graph->xaxis->SetLabelAngle(270);
    
            $graph->legend->Pos(0,0);
            $graph->legend->SetColumns(1);
            $graph->legend->SetFont(FF_SIMSUN, FS_NORMAL,6);
            foreach ($d as $key => $v) {
                $y = array_fill (0, 23, 0);
                $y[$key] = $v;
                $plot = new \BarPlot($y);
                $plot->SetAbsWidth(10);
                $plot->SetLegend(iconv("UTF-8", "GB2312//IGNORE", $names[$key] ?? ''));
                $graph->Add($plot);
                $plot->SetFillColor($c[$key % count($c)]);
            }
    
            $graph->Stroke();
    

    参考文档地址: https://jpgraph.net/download/manuals/classref/index.html

    相关文章

      网友评论

          本文标题:JpGraph 柱状图(bar)复杂 legend+tickLa

          本文链接:https://www.haomeiwen.com/subject/fgamkqtx.html