Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setJsonConfig() #107

Closed
Joshlete opened this issue Oct 18, 2023 · 6 comments
Closed

setJsonConfig() #107

Joshlete opened this issue Oct 18, 2023 · 6 comments

Comments

@Joshlete
Copy link

Joshlete commented Oct 18, 2023

I am a beginner to laravel, and I need to customize the graph to have annotation. This is in my livewire component:

$chart = (new LineChartModel())
            ->setTitle('Simple Chart')
            ->addPoint(10, 30)
            ->addPoint(20, 40)
            ->addPoint(30, 50)
            ->setJsonConfig(json_encode([
                'annotations' => [
                    'xaxis' => [
                        [
                            'x' => 15,
                            'x2' => 25,
                            'borderColor' => '#775DD0',
                            'label' => [
                                'text' => 'Annotation Label',
                                'style' => [
                                    'color' => '#6B5',
                                    'background' => '#775DD0',
                                ],
                            ],
                        ],
                    ],
                ]
            ]));

$lineChartModels[] = $chart;

And I return is like this:

return view('livewire.livepos-chart', [
            'lineChartModels' => $lineChartModels
        ]);

This is in the blade file:

<div>
    @foreach($lineChartModels as $lineChartModel)
        <div style="height: 500px">
            <livewire:livewire-line-chart :line-chart-model="$lineChartModel" />
        </div>
    @endforeach
</div>

But this is what I am getting:
image

Ive tried by using json_encode and without using it. I've tried to simplify it as much as possible. But I am not getting any change from using setJsonConfig(). Am I doing something wrong?

@faakher
Copy link

faakher commented Oct 19, 2023

as the docs suggest, while using ->setJsonConfig, you must use dot (.) notation to add nested keys, no need to pass multi array or json_encode.
Instead of passing an array of multiple arrays you should use like this:

->setJsonConfig([
    'fill.type' => 'gradient',
    'fill.gradient.shade' => '',
    'fill.gradient.shadeIntensity' => 0.8,
    'fill.gradient.opacityFrom' => 0.6,
    'fill.gradient.opacityTo' => 0.1,
    'tooltip.enabled' => false,
    'xaxis.show' => true,
    'xaxis.lines.show' => false,
    'xaxis.labels.show' => false,
    'xaxis.stroke.width' => 0,
    'xaxis.axisBorder.show' => false,
    'chart.toolbar.show' => false,
    'chart.height' => 90,
    'markers.colors' => 'transparent',
    'markers.strokeColors' => 'transparent',
    'grid.show' => false,
])

hope it will help you

@Joshlete
Copy link
Author

$chart = (new LineChartModel())
                ->addPoint(10, 30)
                ->addPoint(20, 40)
                ->addPoint(30, 50)
                ->setJsonConfig([
                    'xaxis.show' => false,
                    'title.text' => 'Basic Line Chart',
                    'title.align' => 'left',
                    'chart.background' => '#f0f0f0'
            ]);

That is helpful advice, thank you. Unfortunately, it is still not working. xaxis still shows up, background doesn't change, I can't get a single thing in the setJsonConfig() function to work.

image

@philippnies
Copy link

In v3.0.0, the setJsonConfig method is no longer documented, but is still included in the code.

However, its use does not affect the appearance of the chart.
Has anything changed? I want to change min/max of the Y-Axis

@clarg18
Copy link

clarg18 commented Nov 3, 2023

Yeah, it's not working for me either.

@stijnvanouplines
Copy link
Contributor

This will be fixed when #108 is merged

@asantibanez
Copy link
Owner

#108 has been merged and should address this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants