请帮助我,我需要通过这个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"
}
]
你想用你的SQL结果替换' - > values([5,10,20])'吗?我不明白你的语言对你的代码做一些假设 –
是的兄弟我想用我的sql结果代替 –