|
@@ -7,6 +7,8 @@ class Chart {
|
|
|
private $type = "bar";
|
|
private $type = "bar";
|
|
|
private $datasets = [];
|
|
private $datasets = [];
|
|
|
private $labels = [];
|
|
private $labels = [];
|
|
|
|
|
+
|
|
|
|
|
+ private $xAxes = [];
|
|
|
private $yAxes = [];
|
|
private $yAxes = [];
|
|
|
|
|
|
|
|
private $datalabelSuffixes = [];
|
|
private $datalabelSuffixes = [];
|
|
@@ -16,6 +18,36 @@ class Chart {
|
|
|
$this->id = bin2hex(random_bytes(8));
|
|
$this->id = bin2hex(random_bytes(8));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function addXAxis($options = []) {
|
|
|
|
|
+
|
|
|
|
|
+ $type = $options["type"] ?? "linear";
|
|
|
|
|
+ $position = $options["position"] ?? "bottom";
|
|
|
|
|
+ $id = $options["id"] ?? "x-axis";
|
|
|
|
|
+ $grid_lines = $options["grid_lines"] ?? true;
|
|
|
|
|
+ $tick_config = $options["tick_config"] ?? null;
|
|
|
|
|
+ $scale_label_config = $options["scale_label_config"] ?? null;
|
|
|
|
|
+
|
|
|
|
|
+ $axis = [
|
|
|
|
|
+ "type" => $type,
|
|
|
|
|
+ "display" => true,
|
|
|
|
|
+ "position" => $position,
|
|
|
|
|
+ "id" => $id,
|
|
|
|
|
+ "gridLines" => [
|
|
|
|
|
+ "drawOnChartArea" => $grid_lines
|
|
|
|
|
+ ],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if($tick_config) {
|
|
|
|
|
+ $axis["ticks"] = $tick_config;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($scale_label_config) {
|
|
|
|
|
+ $axis["scaleLabel"] = $scale_label_config;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->xAxes[] = $axis;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function addYAxis($type, $position, $id, $grid_lines = true, $tick_config = []) {
|
|
public function addYAxis($type, $position, $id, $grid_lines = true, $tick_config = []) {
|
|
|
|
|
|
|
|
$axis = [
|
|
$axis = [
|
|
@@ -111,9 +143,16 @@ class Chart {
|
|
|
],
|
|
],
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- if($this->yAxes) {
|
|
|
|
|
|
|
+ if($this->xAxes || $this->yAxes) {
|
|
|
$object->options->scales = new stdClass;
|
|
$object->options->scales = new stdClass;
|
|
|
- $object->options->scales->yAxes = $this->yAxes;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if($this->xAxes) {
|
|
|
|
|
+ $object->options->scales->xAxes = $this->xAxes;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($this->yAxes) {
|
|
|
|
|
+ $object->options->scales->yAxes = $this->yAxes;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if($this->datalabelSuffixes) {
|
|
if($this->datalabelSuffixes) {
|