mbo2olivier / mukadi-chartjs-builder Goto Github PK
View Code? Open in Web Editor NEWgenerate beautiful charts directly from SQL query in PHP
generate beautiful charts directly from SQL query in PHP
Hi there,
I've been trying to stack datas on the same bar in a bar chart but keep failing, has anyone ever tryed this option?
Below is my code in my controller:
$queryTotalPerSeason = $subscriptionRepository->getQueryForTotalPerSeason();
$totalBuilder
->query($queryTotalPerSeason)
->addDataSet('totalFemale', 'Femmes', [
"backgroundColor" => self::TOTAL_PALETTE_F,
])
->addDataSet('totalMale', 'Hommes', [
"backgroundColor" => self::TOTAL_PALETTE_H,
])
->labels('seasonName');
$totalChart = $totalBuilder->buildChart('total-chart', Chart::BAR);
$totalChart->pushOptions([
'scales' => ([
'xAxes' => ([
'stacked' => 'true'
]),
'yAxes' => ([
'stacked' => 'true'
]),
])
]);
Here is my query:
public function getQueryForTotalPerSeason(): string
{
return "SELECT case when subscriber.gender= 'H' then count(subscription.subscriber) else 0 end AS totalMale,
case when subscriber.gender= 'F' then count(subscription.subscriber) else 0 end AS totalFemale,
season.name AS seasonName
FROM App\Entity\Subscription subscription
JOIN App\Entity\Season season
WITH season.id=subscription.season
JOIN App\Entity\Subscriber subscriber
WITH subscriber.id=subscription.subscriber
GROUP BY seasonName, subscriber.gender";
}
I have tryed to 'stacked : true' only on xAxes, only on yAxes, on both , I also tryed to add stack in the addDataSet:
->addDataSet('totalFemale', 'Femmes', [
"backgroundColor" => self::TOTAL_PALETTE_F,
"stack" => "0"
])
But nothing seems to work, I keep having 2 bars side to side, with a duplicate seasonName under each of them.
May this option not be available in this library?
Many thanks for your help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.