2014-05-08 37 views
0

你好我正在爲我的系統做一個grafic與highcharts plugin cakephp現在的問題是,我試圖在3D中做這個grafic,高圖有這個選項,但沒有在我的系統中找到,這是我的代碼:highcharts插件cakephp選項爲3d未找到

控制器一切工作正常,但不是在3D

public function columnacompra($id = null) 
    { 
     $this->loadModel('Soya'); 
     $this->loadModel("SoyaProductorCompra"); 
     $years = $this->SoyaProductorCompra->getYears(); 
     $distinct_years = array(); 
     foreach($years as $year) { 
      $distinct_years[] = $year[0]['distinct_year']; 
     } 
     $this->set(compact('distinct_years')); 

     if (!$id) { 
       $this->Session->setFlash('Porfavor provea un id de usuario'); 
       $this->redirect(array('action'=>'index')); 
     } 
     $user = $this->Soya->findById($id); 
     if (!$user) { 
       $this->Session->setFlash('El id proporcionado no es valido'); 
       $this->redirect(array('action'=>'index')); 
     } 
     if (!$this->request->data) { 
       $this->request->data = $user; 
     } 

     $SoyaMensual = array(120, 265, 245, 120, 265, 245,120, 265, 245,120, 265, 245); 
     $SoyaDiario = array(120, 265, 245, 120, 265, 245,120, 265, 245,120, 265, 245); 

     $chartName = 'Stacked Grouped Column Chart'; 

     $mychart = $this->HighCharts->create($chartName, 'column'); 

     $this->HighCharts->setChartParams(
      $chartName, 
      array(
       'renderTo'   => 'columnwrapper', // div to display chart inside 
       'options3dEnabled' => true, //not found 
       'chartWidth'   => 1000, 
       'chartHeight'   => 750, 
       'chartBackgroundColorLinearGradient' => array(0,0,0,300), 
       'chartBackgroundColorStops'  => array(array(0,'rgb(217, 217, 217)'),array(1,'rgb(255, 255, 255)')), 
       'title'    => 'Tabla Comparativa', 
       'subtitle'    => 'Soya Compras', 
       'xAxisLabelsEnabled'  => TRUE, 
       'xAxisCategories'   => array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'), 
       'yAxisTitleText'  => 'Cantidad en (TM)', 
       'enableAutoStep'  => FALSE, 
       'creditsEnabled'  => FALSE, 
       'plotOptionsSeriesStacking'  => 'normal' 

      ) 
     ); 

     $johnSeries = $this->HighCharts->addChartSeries(); 
     $janeSeries = $this->HighCharts->addChartSeries(); 

     $johnSeries->addName('Mensual') 
      ->addData($SoyaMensual) 
      ->stack = 'compra'; 

     $janeSeries->addName('Diario') 
      ->addData($SoyaDiario) 
      ->stack = 'compra'; 


     $mychart->addSeries($johnSeries); 
     $mychart->addSeries($janeSeries); 



    } 

的看法是這裏

<div class="actions"> 
<h3>Acciones</h3> 
<ul> 
<li><?php echo $this->Html->link("Volver Atras", array('action'=>'graficas', $this->data['Soya']['id'])); ?></li> 
</ul> 
</div> 


<div class="chart"> 
    <h2>Tabla Comparativa de la cantidad de compras</h2>  

<?php echo $this->Html->script('modules/exporting');?> 
<?php echo $this->Html->script('highcharts-3d');?> 

    <div id="columnwrapper" style="display: block; float: left; width:90%; margin-bottom: 20px;"></div> 
    <div class="clear"></div> 

    <?php echo $this->HighCharts->render('Stacked Grouped Column Chart'); ?> 
</div> 

回答

0

根據他們的代碼,CakePHP會使用3.x版本,而3D圖表是在4.x版本中引入的。我想那是不支持的。

1

截止到前幾天,CakePHP Highcharts plugin已更新爲支持3D圖表。您可以在Github上的插件的演示代碼中找到有關如何實現它的代碼示例。

這裏是你將如何設置你的控制器動作對於3D柱形圖:

public function column3d() { 

      $chartData = array(
       29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4 
      ); 

      $chartName = 'Column 3D Chart'; 

      $mychart = $this->Highcharts->create($chartName, 'column'); 

      $this->Highcharts->setChartParams($chartName, array(
       'renderTo' => 'column3dwrapper', // div to display chart inside 
       'chartWidth' => 1000, 
       'chartHeight' => 750, 
       'title' => '3D Column Chart Demo', 
       'subtitle' => 'Source: World Bank', 
       'options3d' => array(
        'enabled' => true, 
        'alpha' => 15, 
        'beta' => 15, 
        'depth' => 50, 
        'viewDistance' => 25 
       ), 
       'xAxisLabelsEnabled' => true, 
       'yAxisTitleText' => 'Units', 
       'enableAutoStep' => false, 
       'creditsEnabled' => false, 
       ) 
      ); 

      $series = $this->Highcharts->addChartSeries(); 

      $series->addName('3D Series') 
        ->addData($chartData); 

      $mychart->addSeries($series); 

      $this->set(compact('chartName')); 
    } 

在你column3d.ctp視圖文件中,可以執行以下操作:

<div class="chart"> 
    <h4>Column 3D Chart</h4> 

    <div id="column3dwrapper" style="display: block; float: left; width:90%; margin-bottom: 20px;"></div> 
    <div class="clear"></div> 

    <?php echo $this->Highcharts->render($chartName); ?>