Coder Social home page Coder Social logo

Comments (4)

dustinnulf avatar dustinnulf commented on August 18, 2024 1

Hi purplelady,

I have the same problem with the plugin. I stepped into the debugger and found an odd constructor name of 'e', which didn't jive with an expected 'line' or 'bar' name. Perhaps there is a mixup in using .min.js versus .js files. I didn't try to pin it down further.

HOWEVER... I looked at the plugins page again: https://gionkunz.github.io/chartist-js/plugins.html
Scrolling down to the very bottom of the 'example plugin' code, it appeared to be the Point Labels code that I wanted. Hey! Cool. So, instead of including the external plugin, copy/paste this code into your <script> section.

function ctPointLabels(options) {
    return function ctPointLabels(chart) {
        var defaultOptions = {
            labelClass: 'ct-label',
            labelOffset: {
                x: 0,
                y: -10
            },
            textAnchor: 'middle'
        };
        
        options = Chartist.extend({}, defaultOptions, options);

        if (chart instanceof Chartist.Line) {
            chart.on('draw', function (data) {
                if (data.type === 'point') {
                    data.group.elem('text', {
                        x: data.x + options.labelOffset.x,
                        y: data.y + options.labelOffset.y,
                        style: 'text-anchor: ' + options.textAnchor
                    }, options.labelClass).text(data.value.y);  // 07.11.17 added ".y"
                }
            });
        }
    }
}

Now, in your plugins definitions of the Chartist options, call the local function instead of the external Chartist.plugins.ctPointLabels:

plugins: [

     ctPointLabels({
         textAnchor: 'middle'
     })

 ]

Run and test. It works on my graph! Let me know if that works for you.

-Dustin

from chartist-plugin-pointlabels.

dustinnulf avatar dustinnulf commented on August 18, 2024

Solved?

from chartist-plugin-pointlabels.

purplelady105 avatar purplelady105 commented on August 18, 2024

@dustinnulf Nope, I am still unable to get the point labels working.

from chartist-plugin-pointlabels.

purplelady105 avatar purplelady105 commented on August 18, 2024

from chartist-plugin-pointlabels.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.