Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

chart js two layer label

var ctx = $("#c");
var myChart = new Chart(ctx, {
  type: 'line',
  data: {
    labels: ["January;2015", "February;2015", "March;2015", "January;2016", "February;2016", "March;2016"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3]
    }]
  },
  options: {
    scales: {
      x: {
        ticks: {
          callback: function(label) {
            let realLabel = this.getLabelForValue(label)
            var month = realLabel.split(";")[0];
            var year = realLabel.split(";")[1];
            return month;
          }
        }
      },
      xAxis2: {
        type: "category",
        grid: {
          drawOnChartArea: false, // only want the grid lines for one axis to show up
        },
        ticks: {
          callback: function(label) {
            let realLabel = this.getLabelForValue(label)

            var month = realLabel.split(";")[0];
            var year = realLabel.split(";")[1];
            if (month === "February") {
              return year;
            } else {
              return "";
            }
          }
        }
      },
      y: {

        beginAtZero: true

      }
    }
  }
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #chart #js #layer #label
ADD COMMENT
Topic
Name
4+2 =