Skip to main content
Topic: [solved] Chart not displaying (Read 2018 times) previous topic - next topic

[solved] Chart not displaying

Hello,

I'm using PHPRad Classic 2.7.3.
I followed the guides and videos on how to create a chart, but I cannot get it to display anything.

When I look at the code with inspector, I see that there are errors with jquery:
Code: [Select]
[Error] TypeError: labels.slice is not a function. (In 'labels.slice(me.minIndex, me.maxIndex + 1)', 'labels.slice' is undefined)
(anonymous function) (jquery-3.3.1.min.js:2:31048)
[Error] TypeError: undefined is not an object (evaluating 'tooltip.initialize')
eventHandler (chartjs-2.3.0.js:4491)
(anonymous function) (chartjs-2.3.0.js:4415)
(anonymous function) (chartjs-2.3.0.js:5545)
How can I fix this?




Re: Chart not displaying

Reply #4
Thank you Willvin for your help.

Regarding the chart, I have another question.
I have this query:
Code: [Select]
"SELECT  f.year, SUM(f.revenue) AS sum_of_revenue FROM financials AS f WHERE  (f.client_id  =14 ) GROUP BY f.year"
And I want to make the chart to display on the client view page, so I need to use a dynamic value for the WHERE clause.
I've seen your recommendation in another post to use
Code: [Select]
<?php echo $data['field name goes here'] ; ? >
However I receive an error when I do this:
Code: [Select]
"SELECT  f.year, SUM(f.revenue) AS sum_of_revenue FROM financials AS f WHERE  (f.client_id  = " . $data['id'] . " ) GROUP BY f.year"
The error is:
Quote
Notice: Undefined variable: data in /volume1/virtual_hosts/phprad/ts/app/controllers/SharedController.php on line 158
But when I add a CustomView component above the chart component and add as Customcode:
Code: [Select]
<?php echo $data['id'] ; ?>
It shows 14 (as it should). So the variable is not undefined.
How can I use data from the current record/view for the WHERE clause?

Re: Chart not displaying

Reply #5
@Erwin‍ the code that handles the chart data function is totally separate from the page that it is placed on. For that, you can only use the global variable like USER_ID, USER_NAME, etc. check the View Helper for more. you can find all chart queries in app/controllers/SharedController.php.

Re: Chart not displaying

Reply #6
I’m confused Willvin. In this post by Emman he attached a video that clearly shows how it does work.
https://phprad.com/forum/index.php?topic=421.msg1213#msg1213
It’s at 10:40 where he uses $sales_detail_category (sales_detail is a database view and category a field).

Re: Chart not displaying

Reply #7
@Erwin‍ that is from the nav menu component, he added the filter component and that variable was created, which allowed him to have access to it. You cannot access variable on the current page where the chart is. All components added to a page is created in the SharedController.php file, so the nav menu and the chart component exist in the same file and the variable for the nav component was available for him to use in his query. Try creating components on the page design and take a look at the SharedController.php file, you will understand the whole concept. 

Re: Chart not displaying

Reply #8
@willvin Ahaa, ok I understand that. Thank you.

But what I don't understand is how on the same page, this code:

Shows 14 (and that's correct)

And this works too and shows the chart:


But this:


results in an error:
Notice: Undefined variable: data in /volume1/virtual_hosts/phprad/ts/app/controllers/SharedController.php on line 129

Re: Chart not displaying

Reply #9
@willvin Ok, I get that $data['id'] isn't in SharedController.php

As I want to code or change the code the least as possible (because after publishing I have to re-edit the code and I don't want that), what else can I do without coding manually  and still get WHERE filtered data for the chart?

Re: Chart not displaying

Reply #10
Willvin had the solution :)

In "Chart Dataset > Data Source > open the Query builder" and set "Query Params" to:
Code: [Select]
get_session("your_variable")

On the Page Events, select the Page you want to use the variable on, Click BeforeView and add:
Code: [Select]
clear_session("your_variable");
set_session("your_variable", $rec_id);

Re: [solved] Chart not displaying

Reply #11
Hi Erwin & Willvin....
Can you share here the solutions of the topics (Chart not Display), so anyone who facing the same issue can get the solution either.
Thanks....