Home Forums Chart Support Creating a chart from data with SQL DB [PHP]

Creating a chart from data with SQL DB [PHP]

Viewing 15 posts - 1 through 15 (of 15 total)
  • #22120

    Hello, I would like to create a graph on the HTML page to present weather data that is stored in the SQL database. Unfortunately, I have no experience with Canvas JS. Internet forums have not solved my problems. Does anyone have any simple working example? How to do it?

    Thank you in advance for your answer!

    #22123

    @d3bsky,

    Please refer Chart Data from Database for an example on rendering chart with data from database.
    PHP Chart with Data from Database
    You can also download PHP samples from our Download Page and checkout the examples.


    Vishwas R
    Team CanvasJS

    #22142

    OK thanks!
    I managed to create a graph so that everything started working, I had to connect the script: jquery.min.js
    However, when I try to connect license files locally, nothing is displayed. The browser detects errors:

    – Uncaught ReferenceError: jQuery is not defined at jquery.canvasjs.min.js: 920
    – Uncaught ReferenceError: $ is not defined at window.onload

    What is the cause of such errors?

    #22145

    @d3bsky,

    $ / jQuery is not defined is caused when jQuery is not loaded in the web-page. Including jQuery should work fine in your case.

    If this doesn’t solve the issue you are facing, kindly create a static HTML file reproducing the issue you are facing and share it over Google-Drive or Onedrive so that we can look into your code and help you out.


    Vishwas R
    Team CanvasJS

    #22155

    OK thanks!
    Problem solved. I need to have 2 files connected: jquery.canvasjs.min and jquery.min.

    I have one more question:
    My database stores the date in the format: 2018-08-04 13:28:2. I would like to extract only an hour and a minute and display them on the X axis.
    Unfortunately, the “valueFormatString property” does not work. How can I solve this problem?

    #22159

    @d3bsky,

    Can you kindly share sample project along with sample database over Google-Drive or Onedrive so that we can look at your code, understand it better and help you out?


    Vishwas R
    Team CanvasJS

    #22166

    Ok, here is an example project with db: Google Drive

    In addition, I would like to show data from the soil and humidity column on one graph. However, I can not add many y-axis. Can you help me?

    #22169

    @d3bsky,

    valueFormatString is used to format numbers and date time values (x-values) that appears on axisX but not for labels. Passing x-value to dataPoints should work fine in your case dps.push({"x":new Date(result[i].time), "y":result[i].humidity});.

    To format labels, you can use labelFormatter.
    Formatting labels using labelformatter


    Vishwas R
    Team CanvasJS

    #22180

    It works! Thank you. I created a graph with two y-axes. How can I give them names and add a legend?

    • This reply was modified 6 years, 4 months ago by d3bsky.
    #22185

    @d3bsky,

    Legends will be shown for every dataSeries. You can enable legend by setting showInLegend property in dataSeries level to true. Text shown in legend can be set with the help of name or legendText.
    Chart Legends


    Vishwas R
    Team CanvasJS

    #22225

    Thanks!

    #22606

    Can I change the type of time displayed to 24 hour format? Using your advice, I display the hour using: dps.push({"x":new Date(result[i].time), "y":result[i].temp}); on the x-axis I have an hour, however, the date is displayed on the chart next to the value, eg: “02 Sep 18:” Can I change it?

    • This reply was modified 6 years, 3 months ago by d3bsky.
    #22620

    @d3bsky,

    You can set valueFormatString to “HH:mm” to display hours in 24hours format along with minutes. You can customize the format of labels being displayed in axisX using valueFormatString, please refer documentation for more available options.
    Formatting x-axis values


    Vishwas R
    Team CanvasJS

    #23043

    Thanks for help, nowhere I can change the information on how to change the format of the displayed date which is displayed when you hover over a point of the chart. How can I change this?

    #23049

    @d3bsky,

    You can format x-value and y-value displayed in toolTip / indexLabel by setting xValueFormatString and yValueFormatString respectively whereas valueFormatString just defines the format of axis-labels.

    xValueFormatString: "HH:mm",
    yValueFormatString: "#,###.##"
    


    Vishwas R
    Team CanvasJS

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.