|
@@ -7,11 +7,24 @@ class Chart {
|
|
|
private $type = "bar";
|
|
private $type = "bar";
|
|
|
private $datasets = [];
|
|
private $datasets = [];
|
|
|
private $labels = [];
|
|
private $labels = [];
|
|
|
|
|
+ private $yAxes = [];
|
|
|
|
|
|
|
|
public function __construct() {
|
|
public function __construct() {
|
|
|
$this->id = bin2hex(random_bytes(8));
|
|
$this->id = bin2hex(random_bytes(8));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function addYAxis($type, $position, $id, $grid_lines = true) {
|
|
|
|
|
+ $this->yAxes[] = [
|
|
|
|
|
+ "type" => $type,
|
|
|
|
|
+ "display" => true,
|
|
|
|
|
+ "position" => $position,
|
|
|
|
|
+ "id" => $id,
|
|
|
|
|
+ "gridLines" => [
|
|
|
|
|
+ "drawOnChartArea" => $grid_lines
|
|
|
|
|
+ ],
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function getID() {
|
|
public function getID() {
|
|
|
return $this->id;
|
|
return $this->id;
|
|
|
}
|
|
}
|
|
@@ -33,6 +46,8 @@ class Chart {
|
|
|
$background_colours = $options["background_colours"] ?? false;
|
|
$background_colours = $options["background_colours"] ?? false;
|
|
|
$border_colours = $options["border_colours"] ?? false;
|
|
$border_colours = $options["border_colours"] ?? false;
|
|
|
$border_width = $options["border_width"] ?? false;
|
|
$border_width = $options["border_width"] ?? false;
|
|
|
|
|
+ $y_axis_id = $options["y_axis_id"] ?? false;
|
|
|
|
|
+ $type = $options["type"] ?? false;
|
|
|
|
|
|
|
|
$dataset = [
|
|
$dataset = [
|
|
|
"label" => $label,
|
|
"label" => $label,
|
|
@@ -42,6 +57,8 @@ class Chart {
|
|
|
if($background_colours) $dataset["backgroundColor"] = $background_colours;
|
|
if($background_colours) $dataset["backgroundColor"] = $background_colours;
|
|
|
if($border_colours) $dataset["borderColor"] = $border_colours;
|
|
if($border_colours) $dataset["borderColor"] = $border_colours;
|
|
|
if($border_width) $dataset["borderWidth"] = (int) $border_width;
|
|
if($border_width) $dataset["borderWidth"] = (int) $border_width;
|
|
|
|
|
+ if($y_axis_id) $dataset["yAxisID"] = $y_axis_id;
|
|
|
|
|
+ if($type) $dataset["type"] = $type;
|
|
|
|
|
|
|
|
$this->datasets[] = $dataset;
|
|
$this->datasets[] = $dataset;
|
|
|
|
|
|
|
@@ -53,30 +70,38 @@ class Chart {
|
|
|
|
|
|
|
|
public function getJSON() {
|
|
public function getJSON() {
|
|
|
|
|
|
|
|
- return json_encode([
|
|
|
|
|
|
|
+ $object = (object) [
|
|
|
"type" => $this->type,
|
|
"type" => $this->type,
|
|
|
- "data" => [
|
|
|
|
|
|
|
+ "data" => (object) [
|
|
|
"labels" => $this->labels,
|
|
"labels" => $this->labels,
|
|
|
"datasets" => $this->datasets
|
|
"datasets" => $this->datasets
|
|
|
],
|
|
],
|
|
|
- "options" => [
|
|
|
|
|
- "title" => [
|
|
|
|
|
|
|
+ "options" => (object) [
|
|
|
|
|
+ "title" => (object) [
|
|
|
"display" => true,
|
|
"display" => true,
|
|
|
"fontSize" => 32,
|
|
"fontSize" => 32,
|
|
|
"fontFamily" => "Roboto",
|
|
"fontFamily" => "Roboto",
|
|
|
"fontStyle" => "300",
|
|
"fontStyle" => "300",
|
|
|
"text" => $this->title
|
|
"text" => $this->title
|
|
|
],
|
|
],
|
|
|
- "legend" => [
|
|
|
|
|
|
|
+ "legend" => (object) [
|
|
|
"position" => "top",
|
|
"position" => "top",
|
|
|
],
|
|
],
|
|
|
- "plugins" => [
|
|
|
|
|
|
|
+ "plugins" => (object) [
|
|
|
"datalabels" => [
|
|
"datalabels" => [
|
|
|
"color" => "white",
|
|
"color" => "white",
|
|
|
],
|
|
],
|
|
|
],
|
|
],
|
|
|
],
|
|
],
|
|
|
- ]);
|
|
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if($this->yAxes) {
|
|
|
|
|
+ $object->options->scales = new stdClass;
|
|
|
|
|
+ $object->options->scales->yAxes = $this->yAxes;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return json_encode($object);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|