Topic: chart from js variable

bissounet free asked 2 years ago


I'm trying to build a chart from data of type {x: 2019-05 / 06, y: 4.5}, {x: 2019-06-15, y: 3.6}, ... coming from a js variable .

This variable was built from a php file (which contains an sql request which depends on a js variable transported by ajax and POST method). Then transport of this php variable (after echo $variable) via ajax to the js script (retrieving a var variable=tmp [0]). But when I enter this variable directly in the datasets: [{data: [variable] ... the curve is not displayed.
On the other hand, when I manualy enter an example of this data between the hooks datasets: [{data: [{x: 2019 ...] everything works normally. I tried to format the js variable to JSON.parse (JSON.stringify (variable)), but it doesn't work.

However, I would like to continue working with my chart.php file without using the php hooks inside my html main page.

Thanks for your help !


Grzegorz Bujański staff commented 2 years ago

it looks like the data is not yet downloaded when the chart is generated. Check that this variable has the correct value before generating the chart. Here you will find an example of how you can generate a chart using data from api: https://mdbootstrap.com/docs/standard/data/charts-advanced/#section-async-data


Grzegorz Bujański staff commented 2 years ago

Unfortunately that example is only available to pro users. I can't paste it here. It looks like you are incorrectly initializing the charts. Use new mbd.Chart instead of new Chart


Adam Jakubowski staff commented 2 years ago

Hello @bissounet,

All questions regarding MDB licensing, products, partnerships, and other non-technical queries - it should be asked directly to contact@mdbootstrap.com

I've reached out to you via the email address assigned to your mdbootstrap account.

Keep coding, Adam From MDB


FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Closed

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.10.1
  • Device: PC
  • Browser: all
  • OS: W10
  • Provided sample code: No
  • Provided link: No