2017-11-13 1 views
1

amchartsを使用してcodechartを作成し、凡例(http://www.amcharts.com/demos/pie-chart-with-legend/)の円グラフを使用してタイトルと値の凡例を表示するデモ。今度は、関連するパーセンテージをそれぞれの行に表示する凡例の別のフィールドを追加します。それを行うためのキーワードや方法はありますか?私はプログラミングが初めてです。 は、ここでは、伝説のvalueTextは、文字列に[[percents]]ショートを追加することによって、パーセントが含まれるようにカスタマイズすることができます。..私のコードですamchartsの凡例に別のフィールドを追加してパーセントを表示する

$data['chartOne'] = $this->prepareJson($totalQuotations, "q"); 
$data['chartTwo'] = $this->prepareJson($totalContribution, "c"); 

<script type = "text/javascript"> 
        var chart1 = AmCharts.makeChart("salesReportPerformanceChartdiv",' . $data["chartOne"] . '); 
        var chart2 = AmCharts.makeChart("salesReportContributionChartdiv",' . $data["chartTwo"] . '); 
       </script>'; 


public function prepareJson($data, $type) { 
    $chatData = []; 
    foreach ($data as $status) { 
     $stustotal = new \stdClass(); 
     $stustotal->y = $status->count; 
     if ($type == "q") { 
      $stustotal->x = $status->status_name; 
     } else if ($type == "c") { 
      $stustotal->x = $status->user_name; 
     } 
     array_push($chatData, $stustotal); 
    } 

    $listeners = new \stdClass(); 
    $listeners->method = addLegendLabel; 
    $listeners->event = "drawn"; 

    $export = new \stdClass(); 
    $export->enabled = true; 

    $legend = new \stdClass(); 
    $legend->position = "right"; 
    $legend->markerType = "circle"; 
    $legend->autoMargins = true; 

    $feOffset = new \stdClass(); 
    $feOffset->result = "offOut"; 
    $feOffset->in = "SourceAlpha"; 
    $feOffset->dx = 0; 
    $feOffset->dy = 0; 

    $feGaussianBlur = new \stdClass(); 
    $feGaussianBlur->result = "blurOut"; 
    $feGaussianBlur->in = "offOut"; 
    $feGaussianBlur->stdDeviation = 5; 

    $feBlend = new \stdClass(); 
    $feBlend->in = "SourceGraphic"; 
    $feBlend->in2 = "blurOut"; 
    $feBlend->mode = "normal"; 

    $filter = new \stdClass(); 
    $filter->id = "shadow"; 
    $filter->width = "200%"; 
    $filter->height = "200%"; 
    $filter->feOffset = $feOffset; 
    $filter->feGaussianBlur = $feGaussianBlur; 
    $filter->feBlend = $feBlend; 

    $defs = new \stdClass(); 
    $defs->filter = $filter; 

    $chart = new \stdClass(); 
    $chart->type = "pie"; 
    $chart->startDuration = 0; 
    $chart->theme = "light"; 
    $chart->addClassNames = true; 
    $chart->legend = $legend; 
    $chart->innerRadius = "85%"; 
    $chart->defs = $defs; 
    $chart->dataProvider = (array)$chatData; 
    $chart->valueField = "y"; 
    $chart->titleField = "x"; 
    $chart->labelRadius = 5; 
    $chart->radius = "42%"; 
    $chart->labelText = ""; 
    $chart->listeners = $listeners; 
    $chart->export = $export; 

    $chartJSON = json_encode($chart); 

    return $chartJSON; 
} 

答えて

0

。デフォルトでは、"[[value]]"に設定されています。あなたのケースでは、それはあなたの$legend変数を通して設定しなければならないようです。

$legend->valueText = "[[value]] [[percents]]%"; //customize as needed 
$legend->valueWidth = 100; //adjust as needed so it doesn't overlap 

Fiddle

+0

ありがとう:あなたはまた、そのような長い値文字列のために対応するためにvalueWidthを設定することをお勧めします!これはうまくいった –

関連する問題