设置chart.js Y轴最大值和步长值

时间:2018-08-21 14:36:17

标签: javascript chart.js

我使用Charts.js编写了一个简单的折线图,该图表通过ajax调用来更新数据。通过更新图表选项,我根据数据设置了y轴最大值和步长值。现在,当我在图例上单击禁用数据集时,需要更新这些值。每当禁用数据集时,如何调用函数来设置这些值?

图表:

stage('Checkout') {
 // Get CalibrationResults from GitHub
 checkout([  
            $class: 'GitSCM', 
            branches: [[name: 'refs/heads/master']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'CalibrationResults']], 
            submoduleCfg: [], 
            userRemoteConfigs: [[credentialsId: '6463627-ab54-4e42-bc29-123458', url: 'https://github.com/AtlasBID/CalibrationResults.git']]
        ])
 // Get Combination from GitHub
 checkout([  
            $class: 'GitSCM', 
            branches: [[name: 'refs/heads/master']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'Combination']], 
            submoduleCfg: [], 
            userRemoteConfigs: [[credentialsId: '6463627-ab54-4e42-bc29-123458', url: 'https://github.com/AtlasBID/Combination.git']]
        ])
 // Get CombinationBuilder from GitHub
 checkout([  
            $class: 'GitSCM', 
            branches: [[name: 'refs/heads/master']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'CombinationBuilder']], 
            submoduleCfg: [], 
            userRemoteConfigs: [[credentialsId: '6463627-ab54-4e42-bc29-123458', url: 'https://github.com/AtlasBID/CombinationBuilder.git']]
        ])

}

从ajax获取数据集后调用的函数:

var mainChart = new Chart(ctx, {
  type: 'line',
  options: {
    scales: {
      yAxes: [{
        ticks: {
          beginAtZero: true,
          callback: function(v) {
            // fornating tick labels
          },
        },
      }]
    },
    tooltips: {
      callbacks: {
        label: function(tooltipItem, data) {
          // formatting tooltip labels
        }
      }
    },
  },
});

0 个答案:

没有答案