Unable to update labels on Chart.js 2.0 Beta version

I'm facing a dilemma whether this is a bug or if there's something I'm overlooking because I'm unable to apply custom formatting to the y-axis labels on my Chart.js 2.0 Beta bar chart.

Referencing the Chart.js 2.0 Beta Docs, here are the configuration options:

Chart.js 2.0 Beta Docs

Below are the configuration options for my bar chart:

options: {
  maintainAspectRatio: false,
  responsive: true,
  scales: {
    xAxes: [
      {
        stacked: true,
        gridLines: {
          show: false
        }
      }
    ],
    yAxes: [
      {
        stacked: true,
        display: true,
        labels: {
          show: false
        }
      }
    ]
  }

options: {
    // Boolean - if true, bars stack on top of each other
    stacked: false,

    hover: {
        // String - We use a label hover mode since the x axis displays data by the index in the dataset
        mode: "label"
    },

    scales: {
        // The bar chart officially supports only 1 x-axis but uses an array to keep the API consistent. Use a scatter chart if you need multiple x axes. 
        xAxes: [{
            // String - type of axis to use. Should not be changed from 'dataset'.
            scaleType: "dataset", // scatter should not use a dataset axis

            // Boolean - if true, show the scale
            display: true,

            // String - position of the scale. possible options are "top" and "bottom" for dataset scales
            position: "bottom",

            // String - id of the axis so that data can bind to it
            id: "x-axis-1", // need an ID so datasets can reference the scale

            // grid line settings
            gridLines: {
                // Boolean - if true, show the grid lines
                show: true,

                // String - color of the grid lines
                color: "rgba(0, 0, 0, 0.05)",

                // Number - width of the grid lines
                lineWidth: 1,

                // Boolean - if true draw lines on the chart area
                drawOnChartArea: true,

                // Boolean - if true draw ticks in the axis area
                drawTicks: true,

                // Number - width of the grid line for the first index (index 0)
                zeroLineWidth: 1,

                // String - color of the grid line for the first index
                zeroLineColor: "rgba(0,0,0,0.25)",

                // Boolean - if true, offset labels from grid lines
                offsetGridLines: false,
            },

            // label settings
            labels: {
                // Boolean - if true show labels
                show: true,

                // String - template string for labels
                template: "<%=value%>",

                // Number - label font size
                fontSize: 12,

                // String - label font style
                fontStyle: "normal",

                // String - label font color
                fontColor: "#666",

                // String - label font family
                fontFamily: "Helvetica Neue",
            },
        }],
        yAxes: [{
            // String - type of axis. 'linear' is the default but extensions may provide other types such as logarithmic
            scaleType: "linear",

            // Boolean - if true, show the scale
            display: true,

            // String - position of axis. Vertical axes can have either "left" or "right"
            position: "left",

            // ID of the axis for data binding
            id: "y-axis-1",

            // grid line settings
            gridLines: {
                // Boolean - if true, show the grid lines
                show: true,

                // String - color of the grid lines
                color: "rgba(0, 0, 0, 0.05)",

                // Number - width of the grid lines
                lineWidth: 1,

                // Boolean - if true draw lines on the chart area
                drawOnChartArea: true,

                // Boolean - if true draw ticks in the axis area
                drawTicks: true,

                // Number - width of the grid line representing a numerical value of 0
                zeroLineWidth: 1,

                // String - color of the grid line representing a numerical value of 0
                zeroLineColor: "rgba(0,0,0,0.25)",
            },

            // Boolean - if true ensures that the scale always has a 0 point
            beginAtZero: false,

            // Object - if specified, allows the user to override the step generation algorithm.
            //          Contains the following values
            //              start: // number to start at
            //              stepWidth: // size of step
            //              steps: // number of steps
            override: null,

            // label settings
            labels: {
                // Boolean - if true show labels
                show: true,

                // String - template string for labels
                template: "<%=value%>",

                // Function - if specified this is passed the tick value, index, and the array of all tick values. Returns a string that is used as the label for that value
                userCallback: null,

                // Number - label font size
                fontSize: 12,

                // String - label font style
                fontStyle: "normal",

                // String - label font color
                fontColor: "#666",

                // String - label font family
                fontFamily: "Helvetica Neue",
            },
        }],
    },
};

Despite the functioning of the chart being fine, I've encountered this specific issue. I've also attempted altering the labels on the provided demo charts that come with the Beta, but the outcomes have remained consistent.

Answer №1

Give it a shot:

dimensions: {
    xAxes: [{
        markings: {
            customFunction: function(value, index, values) { return value; }
        }
    }]
}

Simply replace 'markings' with 'dimensions' and 'customFunction' with 'userCallback'.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for creating an infinite repeating loop in jQuery

I'm attempting to create a jQuery infinite loop featuring images within a div. I've experimented with using the setInterval function, but encountered an issue where the animation starts after a 3-second delay and does not seamlessly repeat itself ...

How to inject a variable into an AngularJS service that utilizes both $http and $interval functions?

Struggling with $http and $interval, I stumbled upon this code. http://embed.plnkr.co/fSIm8B/script.js I forked it here: http://plnkr.co/edit/Al8veEgvESYA0rhKLn1q To make it more functional, how can I pass a variable to the service? Here is the broken ...

Alerting JavaScript with element Selector doesn't function at full capacity

I am currently implementing Notify JS from the following source : Below is the HTML code I am using: <div> <p><span class="elem-demo">aaaa</span></p> <script> $(".elem-demo").notify( "Hello Box" ...

Rendering deeply nested data in a Vue table

I am currently in the process of updating some older code, transitioning to Vue as a replacement. Everything has been going smoothly except for one specific table that is templated using handlebars. With handlebars and nested {{each}} loops, I can easily ...

Learn how to instruct ajax to fetch the designated information and retrieve corresponding data from the database based on the selected criteria

Looking for some help with my 2 select boxes. The first box allows users to choose a brand, while the second box should display products from that brand fetched from the database. Unfortunately, I'm not familiar with AJAX and the script provided by a ...

What is the best way to say hello using jQuery?

I need some assistance with a task that involves entering my name into an input field, clicking a button, and having an h1 tag display below the input saying Hello (my name)! Unfortunately, I am struggling to figure out how to achieve this. Below is the H ...

Storing JWT API tokens in a secure location

Currently, I am in the process of developing the API portion for an application and focusing on implementing JWT authentication. At this point, I am generating a token and sending it back to the front-end as part of a JSON object when a user is created. Ho ...

Tips on keeping a div element in a fixed position until triggered by jQuery

I've managed to create a navigation bar within a header that sticks to the top of the screen once you scroll down past 100px. The functionality works well, but I'm looking to make the navigation bar stay fixed on the right until it snaps, essenti ...

Chat box custom scrollbar always positioned at the bottom

I have a personalized chat box where I included overflow-y for scrolling functionality. However, every time I input a message in the text box, it displays at the top of the scrollbar window. Is there a way to automatically show the most recent message I ...

Ways to implement variables in Jade that are transmitted through res.render

Firstly, I would like to apologize for any errors in my English. In my router file, I have the following code: exports.index = function (req, res) { res.render('./game/main', {name:req.session.name, menuOp:'Home'}); } Additionally, ...

Switch out the view div element with ui-router

Currently, I am utilizing Angular ui-router to manage various views in the following manner: <div ui-view="header"></div> <div ui-view="nav"></div> <div ui-view></div> Upon Angular loading, the divs are automatically p ...

"Combining the power of Angularjs and the state

I've been delving into Redux, mainly in the context of using it with React. However, I use AngularJS. Is there a compelling advantage to implementing Redux instead of handling state within AngularJS scope and letting Angular manage the bindings? ...

Using jQuery to enable scrolling and dynamically changing classes

I'm currently working on enhancing my website with a feature that changes the opacity of the first section to 0.4 when a user scrolls more than 400 pixels down the page. I attempted the following code without success: if($("html, body").offset().top ...

Initializing a table with data will only function properly when a breakpoint is set

Using the bootstrap-table library, I initialize a table with data fetched via ajax request. var arr = []; var getRows = function () { $.ajax({ type: "GET", url: hostUrl, contentType: "app ...

Show the MySQL query results in a pop-up alert box

I need assistance with querying a MySQL database for certain results using PHP and then displaying the result in an alert dialog box through JavaScript. I am able to connect to the database, query the data successfully, and display it on a PHP page. Howeve ...

saving the hash key in a separate array

Currently, I have a collection of key-value pairs that need to be stored in another array. However, I am facing difficulties with the logic as I am unable to keep track of which keys-values have already been assigned while iterating over the list of object ...

Jquery draggable droppable does not support displaying multiple divs simultaneously

I tried to implement the jquery ui draggable and droppable features to display 3 divs within a designated area. Below is the code snippet: --CSS: #content-1 { width: 200px; height: 100px; border: 1px solid red; display: none; } #content-2 { width: ...

What is the best way to change the state of an Object?

I need to dynamically adjust the internalstatus based on the values of externalValues. If valueOne is true, then I want statusOne to be true. Similarly, if valueTwo is true, I want statusTwo to be true and statusOne to be false. const externalValues = { v ...

Retrieve a JavaScript file located in a separate folder

I'm facing an issue with a project that has the following layout: project | - public | - -index.html src | - -index.js The code I am using to import the file is as follows: <script src="../src/index.js"></script> H ...

Streamlining async/await in for loops using Promise.all: A guide

I'm trying to understand how Promise.all() works in this code. I've learned that you can execute async operations concurrently with Promise.all() for better performance. Currently, the code uses nested for-loops (which is not ideal): type ListGro ...