2017-06-14 122 views
0

请帮助我,我需要通过这个SQL线到laravel syxtax使用 https://github.com/ConsoleTVs/Charts SQL语法 即时通讯上使用定制的图表 :创建交互式图表使用laravel

SELECT 
SUM(CASE WHEN status like 'Por Despachar' THEN 1 ELSE 0 END) AS Por_Despachar 
,SUM(CASE WHEN status like 'Planificado' THEN 1 ELSE 0 END) AS Planificado 
,SUM(CASE WHEN status like 'Despachado' THEN 1 ELSE 0 END) AS Despachado 
    FROM presupuesto 

我想在添加此参数这样 enter image description here

这种互动式的图表是我的控制器:

<?php 
 

 
namespace sisVentas\Http\Controllers; 
 

 
use Illuminate\Http\Request; 
 
use sisVentas\User; 
 
use sisVentas\Http\Requests; 
 
use Charts; 
 
class EstadisticaController extends Controller 
 
{ 
 
    // 
 

 
public function index() 
 
    { 
 
    $data = \DB::select(" 
 
      SELECT 
 
       SUM(CASE WHEN status like 'Por Despachar' THEN 1 ELSE 0 END) AS Por_Despachar 
 
       ,SUM(CASE WHEN status like 'Planificado' THEN 1 ELSE 0 END) AS Planificado 
 
       ,SUM(CASE WHEN status like 'Despachado' THEN 1 ELSE 0 END) AS Despachado 
 
      FROM presupuesto 
 
     "); 
 

 

 

 

 

 
     $chart = Charts::create('pie', 'highcharts') 
 
      // Setup the chart settings 
 
      ->title("Resumen de Presupuestos Realizados") 
 
      // A dimension of 0 means it will take 100% of the space 
 
      // This defines a preset of colors already done:) 
 

 
      // You could always set them manually 
 

 
      // Setup the diferent datasets (this is a multi chart) 
 
    ->labels(['Por Despachar', 'Despachado', 'Planificado']) 
 
    ->values([65,10,20]) 
 
    ->dimensions(1000,500) 
 
    ->responsive(false); 
 
     return dd($chart, $data); 
 

 
    } 
 

 
}

Chart {#324 ▼ 
 
    +id: null 
 
    +customId: null 
 
    +type: "pie" 
 
    +library: "highcharts" 
 
    +title: "Resumen de Presupuestos Realizados" 
 
    +element_label: "Element" 
 
    +labels: array:3 [▼ 
 
    0 => "Por Despachar" 
 
    1 => "Despachado" 
 
    2 => "Planificado" 
 
    ] 
 
    +values: array:3 [▼ 
 
    0 => 65 
 
    1 => 10 
 
    2 => 20 
 
    ] 
 
    +colors: [] 
 
    +responsive: false 
 
    +gauge_style: "left" 
 
    +view: null 
 
    +region: "world" 
 
    #suffix: "" 
 
    +container: "" 
 
    +credits: false 
 
    +loader: true 
 
    +loader_duration: 500 
 
    +loader_color: "#000000" 
 
    +background_color: "inherit" 
 
    +template: "material" 
 
    +one_color: false 
 
    +legend: true 
 
    +x_axis_title: false 
 
    +y_axis_title: null 
 
    +"height": 500 
 
    +"width": 1000 
 
} 
 

 
array:1 [▼ 
 
    0 => {#330 ▼ 
 
    +"por_despachar": "3" 
 
    +"planificado": "1" 
 
    +"despachado": "0" 
 
    } 
 
]

+0

你想用你的SQL结果替换' - > values([5,10,20])'吗?我不明白你的语言对你的代码做一些假设 –

+0

是的兄弟我想用我的sql结果代替 –

回答

0

也许不是直接的答案,但应该是有帮助

如果您有任何SQL查询是很难/不可能转换成侃侃而谈,只是使用DB正面。

$data = \DB::select(" 
      SELECT 
       SUM(CASE WHEN status like 'Por Despachar' THEN 1 ELSE 0 END) AS Por_Despachar 
       ,SUM(CASE WHEN status like 'Planificado' THEN 1 ELSE 0 END) AS Planificado 
       ,SUM(CASE WHEN status like 'Despachado' THEN 1 ELSE 0 END) AS Despachado 
      FROM presupuesto 
     "); 

dd($data); 
+0

感谢兄弟我完美地获得了正确的值。你可以帮助我将这些结果传递给图表 –

+0

它应该是' - > values($ data)'或' - > values($ data-> toArray())' –

+0

有了这个 - > values($ data-> toArray())我得到这个错误“调用成员函数toArray()数组”和这个 - > values($ data)方法Illuminate \ View \ View :: __ toString()不能抛出异常 –