PHP code example of bernskioldmedia / laravel-highcharts
1. Go to this page and download the library: Download bernskioldmedia/laravel-highcharts library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bernskioldmedia / laravel-highcharts example snippets
return [
/**
* Default options to be used for all charts.
*/
'defaults' => [],
/**
* Default options to be used for all charts of a specific type.
*/
'defaultsForType' => [
// 'line' => [
// 'title' => [
// 'text' => 'My Line Chart'
// ]
// ]
],
/**
* Defaults for chart labels.
*/
'chartLabels' => [
/**
* CSS styles to be applied to the label.
*/
'styles' => [
// 'fontWeight' => 'bold',
// 'fontSize' => '13px',
],
/**
* Additional Highchart drawing object attributes.
*/
'attributes' => [
'align' => 'center',
],
],
/**
* Defaults for chart lines.
*/
'chartLines' => [
/**
* Highchart drawing object attributes.
*/
'attributes' => [],
],
/**
* Defaults for chart quadrants.
*/
'chartQuadrants' => [
/**
* Highchart drawing object attributes.
*/
'attributes' => [],
],
];
use BernskioldMedia\LaravelHighcharts\Data\DataPoint;
use BernskioldMedia\LaravelHighcharts\Data\Series;
use BernskioldMedia\LaravelHighcharts\Data\Chart;
$chart = Chart::make('test-chart')
->title('Example Bar Chart')
->bar()
->series([
Series::make([
DataPoint::make(
x: '2021-01-01',
y: 10
),
DataPoint::make(
x: '2022-01-01',
y: 20
),
DataPoint::make(
x: '2023-01-01',
y: 30
)
])
]);
$chart = Chart::make('test-chart')
->title('Example Bar Chart')
->bar()
->set('chart.animation', false)
->setMany();
namespace App\Livewire;
use BernskioldMedia\LaravelHighcharts\Concerns\Livewire\InteractsWithCharts;
use BernskioldMedia\LaravelHighcharts\Data\DataPoint;
use BernskioldMedia\LaravelHighcharts\Data\Series;
use Livewire\Component;
class MyChartComponent extends Component
{
use InteractsWithChart;
protected function getChart(): Chart
{
return Chart::make('test-chart')
->title('Example Bar Chart')
->bar()
->series([
Series::make([
DataPoint::make(
x: '2021-01-01',
y: 10
),
DataPoint::make(
x: '2022-01-01',
y: 20
),
DataPoint::make(
x: '2023-01-01',
y: 30
)
])
]);
}
public function render()
{
return view('livewire.my-chart-component');
}
}
use BernskioldMedia\LaravelHighcharts\Data\Chart;
use BernskioldMedia\LaravelHighcharts\Data\ChartExtras;
use BernskioldMedia\LaravelHighcharts\Data\ChartQuadrant;
$chart = Chart::make('test-chart')
->bar()
->extras(function(ChartExtras $extras) {
$extras->addQuadrant(
ChartQuadrant::make()
->from(0, 0)
->to(10, 10)
->attributes([
'fill' => '#000000',
])
);
});
use BernskioldMedia\LaravelHighcharts\Data\Chart;
use BernskioldMedia\LaravelHighcharts\Data\ChartExtras;
use BernskioldMedia\LaravelHighcharts\Data\ChartLine;
$chart = Chart::make('test-chart')
->bar()
->extras(function(ChartExtras $extras) {
$extras->addLine(
ChartLine::make()
->from(0, 0)
->to(10, 10)
->attributes([
'stroke' => '#000000',
])
);
});
use BernskioldMedia\LaravelHighcharts\Data\Chart;
use BernskioldMedia\LaravelHighcharts\Data\ChartExtras;
use BernskioldMedia\LaravelHighcharts\Data\ChartLabel;
$chart = Chart::make('test-chart')
->bar()
->extras(function(ChartExtras $extras) {
$extras->addLabel(
ChartLabel::make()
->coordinates(75, 75)
->styles([
'color' => '#000000',
])
->attributes([
'align' => 'center',
])
);
});