Skip Navigation

[Gelöst] Chart js and Custom fields

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
Chart js and Custom fields

Solution:
Types fields access not available at content template's JS box.

You should try to add your script code within the content template rather adding it to JS box.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/chart-js-and-custom-fields/#post-1081141

Relevant Documentation:

This support ticket is created vor 6 Jahren, 3 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 10 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von SteffenM1628 vor 6 Jahren, 3 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1081093
charts1.png
charts 2.png

Tell us what you are trying to do?

Hey there,
just trying to work with chart.js. Everything works fine (as you can see in the pics). Now i want to parse in the datafields of chart.js my custom field types from toolset. i tried this with the field shortcodes but it doesn´t work.

Hope you can help because this would make toolset even more awesome to create dynamic tables!!!!!!!

This is what i have done:
1. i have created a new template
2. this one goes in the template html field:

<canvas id="myChart"></canvas>

3. this one goes in the js-editor:

var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'line',

    // The data for our dataset
    data: {
        labels: ["January", "February", "March", "April", "May", "June", "July"],  //parse in my custom fields
        datasets: [{
            label: "My First dataset",
            backgroundColor: 'rgb(255, 99, 132)',
            borderColor: 'rgb(255, 99, 132)',
            data: [0, 10, 5, 2, 20, 30, 45],  //parse in my custom
        }]
    },

    // Configuration options go here
    options: {}
});

But when i shortcode is insert it does not parse the value - instead only the shortcode is shown in the front end (pic attached)

Hope you guys have an idea!

Cheers

#1081141

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Types fields access not available at content template's JS box.

what if you try to add your script code within the content template rather adding it to JS box.

For example:

<script type="text/javascript">
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'line',
 
    // The data for our dataset
    data: {
        labels: ["January", "February", "March", "April", "May", "June", "July"],  //parse in my custom fields
        datasets: [{
            label: "My First dataset",
            backgroundColor: 'rgb(255, 99, 132)',
            borderColor: 'rgb(255, 99, 132)',
            data: [0, 10, 5, 2, 20, 30, 45],  //parse in my custom
        }]
    },
 
    // Configuration options go here
    options: {}
});
</script>

Where:
- Add above code to directly to your content template and try to add your Types field to parse.

#1081215

Oh man! So simple but effective. Thank you so much.

Maybe you can help me with some further questions.
So i want to built i dashboard with a table with all posts from the current user = the author of the posts.
So good so far. Now i need the total number of visits and unique visits one specific post has. Where and how can i implement this?

So the chart can show all his post types with the visit count.

cheers

#1081216

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Glad to know that solution I shared works for you and help you to resolve your original issue.

As your original issue is resolved, may I ask you to open a new ticket for your each new question. This will help other users searching on the forum as well as to write correct resolve summary.

Thank you for understanding.

#1081217

No Prob for me. Can you transfer my question. Other Support agents did split the topic.

#1081219

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Well - even I can split the issue but the ticket is in German forum and if I split it it will again went to German forum.

It would be great help if you can create a ticket with English Forum as no German support available at the moment.

Again, thank you for understanding.

#1081220

Done!

#1081253

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Feel free to close this ticket and create new with English support forum.

#1081258

Closed and new topic is created

#1081260

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Sorry - could you please mark this resolved. Thank you 🙂

#1081261