3 Replies - 1244 Views - Last Post: 28 September 2017 - 10:21 AM

#1 hokletrian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-July 17

Custom Charting

Posted 27 September 2017 - 05:17 PM

Hey guys I'm developing a web app which allows the user, once logged in , to create their own highchart in the front end. At the moment i have something really tacky which lets the user select a sensor name from a dropdown, and stores the sensor names selected in a custom chart table. This basically stores strings of the field names which is then executed in another query to produce the chart. I know it's not the best way of doing it , and I'm facing problems such as null values because users might not select all sensors.Also there can only be a fixed amount of sensors to correlate with the array properly. I'm just wondering is there an easier way the user can create their own multiple graphs on the front end which can be saved to a template or DB ? Any help would be great, been busting my head on this one!

Table examples:

Custom Chart table
Posted Image

Data table
Posted Image

Code:
PHP
HTML and JS

Front End Example:
Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: Custom Charting

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1830
  • View blog
  • Posts: 5,761
  • Joined: 15-January 14

Re: Custom Charting

Posted 27 September 2017 - 05:37 PM

If things could be null, you need to check for those values and handle them differently if they need to be handled differently. If things like that are optional then you shouldn't assume that everything is filled in. I'm not sure if the fixed number is something that's required by whatever you're using, but if that's not a requirement then you could just allow them to add another field for another sensor up until some maximum number that you want to set, you could do that dynamically with some Javascript. Your database structure could change to store the sensor values in another table aside from the rest of the chart settings.
Was This Post Helpful? 0
  • +
  • -

#3 hokletrian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-July 17

Re: Custom Charting

Posted 27 September 2017 - 05:54 PM

Cheers for the reply. Its not so much the NULL part which has become the issue its the fact that the user wants multiple charts on "their" page which is saved? I'm not familiar on how i could go about this. With the above code I'm only using one chart which uses 5 variables to populate the array? If some of the variables are empty wont that cause issues? I definitely thought about adding a button which allows them to keep on adding sensor dropdowns, I'm not really sure on how i could do this either.. Sorry I'm relatively new to the scene, if you could link some examples or manuals that would be great :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1830
  • View blog
  • Posts: 5,761
  • Joined: 15-January 14

Re: Custom Charting

Posted 28 September 2017 - 10:21 AM

Quote

If some of the variables are empty wont that cause issues?

I don't know, are you the writing the code to just assume that everything is there or is there some validation and error checking? The code only does what you tell it to do.

There should be plenty of examples or tutorials online about how to use Javascript to add elements to the page. The two general choices would be to either clone a series of elements and add them to the page, or use document.createElement to just create each element and then add everything to the page.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1