1. Go to this page and download the library: Download uneca/plotly-chart-editor 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/ */
use App\Models\Chart;
use Livewire\Attributes\On;
class EditChart extends \Livewire\Component
{
public Chart $chart;
public array $rawDataset;
public function mount(Chart $chart): void
{
$this->chart = $chart;
$this->rawDataset = [
'Country' => ['Ghana', 'Kenya', 'Nigeria'],
'Population' => [34, 55, 223],
'GDP' => [72, 95, 446],
];
}
#[On('chart-synced')]
public function onChartSynced(array $data, array $layout): void
{
$this->chart->update([
'traces' => $data,
'layout' => $layout,
]);
}
public function render()
{
return view('livewire.edit-chart');
}
}
use Livewire\Attributes\On;
use Livewire\Component;
class SaveButton extends Component
{
#[On('chart-synced')]
public function persist(array $data, array $layout): void
{
// Persist $data and $layout
}
public function render(): View
{
return view('livewire.save-button');
}
}
// App\Listeners\SaveChart.php
class SaveChart
{
public function handle(\Uneca\PlotlyChartEditor\Events\ChartSynced $event): void
{
// $event->data, $event->layout
// Save to database, trigger a job, etc.
}
}