chart.jschartjs-2.6.0vue-chartjs

ChartJS for 1 and 0 values display true or false


So I have a chart, with a dataset between 0 - 1 (this reffers wether we have stock or not on a specific date) and withing the chart, instead of printing 1 or 0 for each date, I want it to display Yes or No, or at least True / False

https://nimb.ws/W9CVKI - here you have the current way it displays the data

{
      "labels": [
        "23.02.2019",
        "24.02.2019",
        "25.02.2019",
        "26.02.2019",
        "27.02.2019",
        "28.02.2019",
        "01.03.2019",
        "02.03.2019"
      ],
      "datasets": [
        {
          "label": "Stock evolution",
          "lineTension": 0,
          "borderColor": "#37a1eb",
          "backgroundColor": "transparent",
          "pointBackgroundColor": "#fff",
          "data": [
            1,
            1,
            1,
            0,
            1,
            0,
            1,
            1
          ]
        }
      ]
    }

Solution

  • If you want to generate the desired result along the yAxes, use something similar to this:

    yAxes:[{
        ticks:{
            callback:function(value,index,values){
                if (value == 1) return "True";
                if (value == 0) return "False";
            }
        }
    }]