Trendline Chart JS Plugin not displayed in Symfony with Webpack - symfony

I'm using Chart JS with Symfony UX (composer req symfony/ux-chartjs). I added the plugin chartjs-plugin-trendline.
I load the plugin in my app.js file with
import Chart from 'chart.js';
import chartTrendline from 'chartjs-plugin-trendline';
Chart.plugins.register(chartTrendline);
and compile it.
Then I create my chart in Controller.php like this
$stock_changes_per_day_chart->setData([
'labels' => $stock_changes_per_day_day,
'datasets' => [
[
'label' => 'Number of Stock Changes per Day (last '.$days.' Days)',
'backgroundColor' => '#FF6384',
'borderColor' => '#FF6384',
'data' => $stock_changes_per_day_number,
'trendlineLinear' => [
'colorMin' => "red",
'colorMax' => "green",
'lineStyle' => "dotted",
'width' => 2
]
],
]);
$stock_changes_per_day_chart->setOptions([
'responsive' => true,
'maintainAspectRatio' => false,
]);
Can anybody imagine why the trendline is not displayed in my frontend?
What configuration am I missing?
Thanks!

Related

How to add title to axes with chartjs on Symfony UX

I made a chart with Symfony UX and chartJS. All work but i'm battling with the customization.
Has someone succeed to add titles to axes on a chart with chartjs with Symfony UX. I'm trying differents options but I don't know why the title for yAxes and xAxes don't work.
Here is my code :
$chart->setOptions([
'responsive' => true,
'legend' => ['display' => false],
'title' => [
'display' => true,
'text' => 'Title of the graph',
'fontSize' => 16
],
'scales' => [
'yAxes' => [
'title' => [
'display' => true,
'text' => 'Title for y Axes',
]
],
],
]);
The code for the title works perfectly but the title for yAxes do not work.
Has anyone solve this ?

How to customize the title and tooltip in ux-chartjs?

I made a chart with Symfony UX and chartJs. Everything works but when I want to customize it, it become a problem and I can't find a good docs for that.
My chart is done and now I want to customize the tooltip and the title, I did like that :
$chart->setOptions([
'responsive' => true,
'title' => [
'display' => true,
'text' => 'test',
'color' => '#ce1111',
],
'tooltips' => [
'backgroundColor' => '#ce1111',
'titleColor' => '#000'
]
]);
For the title, it displays 'test' but the color doesn't work even if I replace it with titleColor.
For tooltips the backgroundColor works but not the titleColor.
Anyone has already solved this problem ?
I found it, sorry for the question but the docs is different. I post here how I dit it :
$chart->setOptions([
'responsive' => true,
'title' => [
'display' => true,
'text' => strtoupper('test'),
'fontColor' => '#ce1111',
'fontSize' => 16
//'padding' => 50
],
'tooltips' => [
'backgroundColor' => '#fff',
'bodyFontColor' => '#000',
'bodyFontSize' => 16,
],
'legend' => [
'labels' => [
'fontColor' => "#ce1111",
'fontSize' => 16
]
]
]);

Embedded admin template

I'd like to drastically customise the layout for one particular embedded admin. My block sits like so:
->add('options', CollectionType::class, [
'by_reference' => false,
'label' => false,
], [
'edit' => 'inline',
'inline' => 'table',
])
On the admin block within the .yaml I've tried adding a calls then set template and I've had no luck.
I've also tried:
[
'edit' => 'inline',
'inline' => 'table',
'template' => 'admin/example/example.html.twig'
]
Finally, I also tried within my OptionAdmin using the method setFormTheme().
Any help or suggestions would be much appreciated.

Translations are not saved correctly using A2lix Translation + KnpLabs DoctrineBehaviors

In my Symfony project I use SonataAdminBundle and A2lixTranslationForm + KnpLabsDoctrineBehaviors bundles for multi-language support.
I have Serial and Episode entities which use standard OneToMany and ManyToOne relationship. I display episodes using sonata_type_collection:
->add('episodes', 'sonata_type_collection', [
'by_reference' => false,
],
[
'edit' => 'inline',
'inline' => 'table',
]
)
By default A2lixTranslation bundle displays translatable fields under each other. However, I need to display each translation field of the episode in its own column. In order to achieve this, I created three virtual fields with the same property_path:
->add('episode_title', 'a2lix_translations', [
'property_path' => 'translations',
'fields' => [
'title' => [
'attr' => [
'pattern' => false,
],
'label' => false,
],
],
'exclude_fields' => ['subTitle', 'description'],
'label' => 'Title',
])
->add('episode_subtitle', 'a2lix_translations', [
'property_path' => 'translations',
'fields' => [
'subTitle' => [
'label' => false,
],
],
'exclude_fields' => ['title', 'description'],
'label' => 'Subtitle',
'required' => false,
])
->add('episode_description', 'a2lix_translations', [
'property_path' => 'translations',
'fields' => [
'description' => [
'field_type' => 'textarea',
'label' => false,
],
],
'exclude_fields' => ['title', 'subTitle'],
'label' => 'Description',
'required' => false,
])
As you can see, I display only one field in each a2lix_translations form.
But I faced the following problem: only the last field value (description in this case) is saved when I add new episode using Add new button of the collection form and then clicking Update button of the parent (Serial) form. Wherein already existing episodes are saved correctly if edited.
Could you please point me why is this happening and how to fix the issue. I suppose each translations form values rewrite the previous ones, but why do this work normally when saving existing records?
Or maybe there is another way to display each field in the own column in sonata collection form, this also will be helpful.
Thank you.

Sonata Admin - A2LiX Translation Field + Sonata Formatter Type

I've plugged Formatter (with CKeditor) to the 'content' field in one of my Sonata's Admin classes. This 'content' also has a translation, that's editable through 'a2lix_translations_gedmo' translations type. I've been trying to add CKeditor to this field as well, but it throws exceptions in any configuration I'm trying to set.
Google knows nothing about it, as well as SO. I've also looked in Sonata News Bundle sources (where sonata_formatter_type is implemented), but there are no translations available.
My Formatter field:
->add('content', 'sonata_formatter_type', [
'label' => "Content",
'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(),
'format_field' => 'contentFormatter',
'source_field' => 'rawContent',
'ckeditor_context' => 'my_config',
'source_field_options' => [
'attr' => [
'class' => 'span10', 'rows' => 10
]
],
'listener' => TRUE,
'target_field' => 'content'
])
My Translation fields:
->add('translations', 'a2lix_translations_gedmo', [
'label' => "Управление локализациями",
'translatable_class' => 'AppBundle\Entity\Article',
'fields' => [
'content' => [
'locale_options' => [
'ru' => [
'label' => 'Контент'
]
]
]
]
])
Maybe someone knows how to add 'sonata_formatter_type' to this damn 'a2lix_translations_gedmo' type (or 'a2lix_translations')?
'a2lix_translations_gedmo' or 'a2lix_translations' depends of the translation strategy chosen.
Gedmo strategy is discouraged and you shoud use a more recent translation strategy like the KnpLabs that I recommend. https://github.com/KnpLabs/DoctrineBehaviors#translatable
Othewise, see https://github.com/a2lix/TranslationFormBundle/issues/177#issuecomment-94949480

Resources