close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

chart.js with WA

Thread began 11/03/2020 8:03 am by Jonas | Last modified 11/04/2020 9:25 am by Ray Borduin | 348 views | 5 replies |

Jonas

chart.js with WA

I have found a movie that explains how to create dynamic charts (https://www.youtube.com/watch?v=cREXtrFiJBc).

The problem is that I do not understand how to do this using Webassist tool.

On their page, the database is called with full code, instead of referring to an include page which is common.
The select statement is also created here.
Then each line is looped to create a format that chart.js understands.

I enclose their file, as well as an attempt by me that does not work. Can anyone tell me how to do this with Webassist, thanks!

index.php is the source file that works, indexCopy.php is my attempt.

Attached Files
index.php
indexCopy.php
Sign in to reply to this post

Ray BorduinWebAssist

This code:

php:
//loop through the returned data

    while ($row = mysqli_fetch_array($result)) {

        $data1 = $data1 . '"'. $row['data1'].'",';
        $data2 = $data2 . '"'. $row['data2'] .'",';
    }


should be:

php:
//loop through the returned data

    while (!$sql->atEnd()) {

        $data1 = $data1 . '"'. $sql->getColumnVal("
data1").'",';
        $data2 = $data2 . '"'. $sql->getColumnVal("
data2") .'",';
$sql->moveNext()
    }



I've attached a chart.js user registration chart example I created for another project you might get some ideas from.

Attached Files
users_chart.php
Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

Im sorry, but It only displays the first value from the two datasets, in the chart?
<?php require_once('../../Connections/bucketListHub.php'); ?>
<?php require_once('../../webassist/mysqli/rsobj.php'); ?>
<?php
$data1 = '';
$data2 = '';
?>
<?php
$sql = new WA_MySQLi_RS("sql",$bucketListHub,1);
$sql->setQuery("SELECT * FROM chartTst");
$sql->execute();
?>
<?php
//loop through the returned data
while (!$sql->atEnd()) {

$data1 = $data1 . '"'. $sql->getColumnVal("data1").'",';
$data2 = $data2 . '"'. $sql->getColumnVal("data2") .'",';
$sql->moveNext();
}

$data1 = trim($data1,",");
$data2 = trim($data2,",");
?>

Sign in to reply to this post

Ray BorduinWebAssist

$sql = new WA_MySQLi_RS("sql",$bucketListHub,1);

should be:

$sql = new WA_MySQLi_RS("sql",$bucketListHub,0);

Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

Now, when you say that, it sounds obvious.
For some reason, the number 0 does not appear in my bar graph (it starts at 1 on the y-axes), even though I typed 'beginAtZero: true'.
This is a bit annoying then, it is sometimes only value 1.

Here's the code:
<?php
$data = '';
$label = '';
$colorCode = '';

//loop through the returned data

while (!$rsCount->atEnd()) {

$data = $data . '"'. $rsCount->getColumnVal("countEachCategory").'",';
$label = $label . '"'. $rsCount->getColumnVal("categoryName").'",';
$colorCode = $colorCode . '"'. $rsCount->getColumnVal("colorcode").'",';
$rsCount->moveNext();
}

$data = trim($data,",");
$label = trim($label,",");
$colorCode = trim($colorCode,",");
?>

----

<script>
let labels = [<?php echo $label; ?>]
let data = [<?php echo $data; ?>];
let colors = [<?php echo $colorCode; ?>];

var ctx = document.getElementById("chart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets:
[{
label: '',
data: data,
backgroundColor: colors,
}]
},
options: {
scales: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}],
}
},
tooltips: {
mode: 'index'
},
legend: {
display: false
}
}
});
</script>

Sign in to reply to this post

Ray BorduinWebAssist

You have:
options: {
scales: {
scales: {
yAxes: [{

it should be:
options: {
scales: {
yAxes: [{

,and remove the corresponding close }

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...