Open rohan-nerdster opened 12 months ago
Thanks for adding the issue, I am going to check this as soon as possible.
The same with PieChart.
@ArielMejiaDev can you, please, have a look? Pie and Donut charts are completely useless without working labels.
How are you populating the labels? It works fine for me using a donut chart:
->setLabels(['label one', 'label two']);
Yes, exactly like this:
app(LarapexChart::class)->donutChart()
->addData([1, 2])
->setLabels(['asd', 'dsa']);
Hmm, only difference I have is that I'm calling it slightly differently, but this works for me:
public function build(array $data, array $labels): \ArielMejiaDev\LarapexCharts\DonutChart
{
return $this->chart->donutChart()
->setTitle('Valuations Outcome')
->addData($data)
->setLabels($labels);
}
No, nothing helps.
public function build(): \ArielMejiaDev\LarapexCharts\DonutChart
{
return (new LarapexChart)->donutChart()
->setTitle('Valuations Outcome')
->addData([1, 2, 3, 4])
->setLabels(['Label 1', 'Label 2', 'Label 3', 'Label 4']);
}
Are you on the latest version of Larapex charts?
Yes, installed it today. Did you create the chart using php artisan make:chart ChartName
? Can you share your app/Charts and your method which you use to call it?
I'm using Livewire:
// app/Livewire/MyComponent.php
<?php
namespace App\Livewire;
use ArielMejiaDev\LarapexCharts\DonutChart;
use ArielMejiaDev\LarapexCharts\LarapexChart;
use Livewire\Component;
class MyComponent extends Component
{
public function build(): DonutChart
{
return app(LarapexChart::class)->donutChart()
->setTitle('Some title')
->addData([1, 2, 3])
->setLabels(['Label 1', 'Label 2', 'Label 3']);
}
public function render()
{
return view('livewire.my-component', ['chart' => $this->build()]);
}
}
<!-- resources/views/livewire/my-component.blade.php -->
<div>
{!! $chart->container() !!}
{{ $chart->script() }}
</div>
The same approach works well with other types of charts.
Im having the same issue
Yes I am having the same issue with pie charts.
I would check this issue, sorry for the delay, thanks
Sorry, even after updating to the newest version I am still not seeing the labels update for pie or donut charts.
public function build(): \ArielMejiaDev\LarapexCharts\PieChart
{
$reminder_sent = Reminder::where('sent', 'y')->count();
$reminder_not_sent = Reminder::where('sent', 'n')->count();
return $this->chart->pieChart()
->setTitle('Notifications sent.')
->setSubtitle('09/01/23 - '.Date("m/d/Y"))
->addData([$reminder_sent, $reminder_not_sent])
->setLabels(['Sent', 'Not Sent']);
}
I did notice if you remove the conditional on lines 23 and 25 in larapex-charts/stubs/resources/views/chart/script.blade.php the labels start to work.
Hello, I have the same issue, the labels are not set and the default values are displayed.
I published a fork of the project some days ago and have done some codestyle, bugfixed ect. I tested your code in a laravel 10 project in my version 1.2.3, maybe you can use it too:
https://github.com/marineusde/larapex-charts
working code from @blisstechllc :
(new DonutChart())
->setTitle('Notifications sent.')
->setSubtitle('09/01/23 - '.Date("m/d/Y"))
->addData([5, 10])
->setLabels(['Sent', 'Not Sent']);
@ArielMejiaDev
From what I can tell, in stubs/resources/views/chart/script.blade.php
the following code is what is causing this issue:
@if ($chart->labels())
labels: {!! json_encode($chart->labels(), true) !!},
@endif
When it renders in the blade view by calling $myTable->script()
, it generates the following code for the label:
...
<!--[if BLOCK]><![endif]--> labels: ["My First Label","My Second Label", "My Third Label"],
<!--[if ENDBLOCK]><![endif]-->
...
The simplest fix is just adding an extra line after the initial @if
like this:
@if ($chart->labels())
labels: {!! json_encode($chart->labels(), true) !!},
@endif
Removing the @if
check also fixes the issue for my tables, but I'm not sure if that causes any other issues if labels aren't present. Also in this file are the stacked
and stroke
properties that may be having similar issues since they also have @if
checks around them and can probably be resolved the same way I mentioned above.
sorry the issue still exist
sorry the issue still exist
Did you test my fork, it still works there: https://github.com/marineusde/larapex-charts
The chart still shows the default legend instead of using the given array of labels