热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将缩放重置为chart.js中的初始值?

如何解决《将缩放重置为chart.js中的初始值?》经验,为你挑选了1个好方法。

我是chartjs的新手.我应用了此库的扩展来启用缩放.起初它看起来很棒,但是当我缩放时,我无法返回到我的条形图开始时的原始点.

在此输入图像描述

在此输入图像描述

有谁知道为什么会发生这种情况或我该如何解决?非常感谢你.

var ctx = document.getElementById("canvas").getContext('2d');
var myChart = new Chart(ctx, {
   type: 'bar',
   data: {
      labels: ["08 Aug 2018 02:42 pm","09 Aug 2018 11:24 am","04 Sep 2018 01:23 pm","04 Sep 2018 01:26 pm","04 Sep 2018 01:31 pm","04 Sep 2018 01:33 pm","04 Sep 2018 01:35 pm","04 Sep 2018 01:36 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:40 pm","04 Sep 2018 01:45 pm","04 Sep 2018 01:46 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:53 pm","04 Sep 2018 02:07 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:20 pm","04 Sep 2018 02:30 pm","04 Sep 2018 02:31 pm","04 Sep 2018 02:33 pm","05 Sep 2018 09:30 am","05 Sep 2018 09:31 am","08 Aug 2018 02:42 pm","09 Aug 2018 11:24 am","04 Sep 2018 01:23 pm","04 Sep 2018 01:26 pm","04 Sep 2018 01:31 pm","04 Sep 2018 01:33 pm","04 Sep 2018 01:35 pm","04 Sep 2018 01:36 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:38 pm","04 Sep 2018 01:40 pm","04 Sep 2018 01:45 pm","04 Sep 2018 01:46 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:49 pm","04 Sep 2018 01:53 pm","04 Sep 2018 02:07 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:19 pm","04 Sep 2018 02:20 pm","04 Sep 2018 02:30 pm","04 Sep 2018 02:31 pm","04 Sep 2018 02:33 pm","05 Sep 2018 09:30 am","05 Sep 2018 09:31 am"],

   datasets: [{"label":"Estatura (cm)","backgroundColor":"rgba(0, 100, 150, 0.5)","pointBorderColor":"rgba(26,179,148,1)","data":["68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00","68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00"]}]

   },
    options: {
      legend: {
        position: 'top',
      },
      scales: {
        xAxes: [{
          ticks: {
            autoSkip: true,
            maxRotation: 0,
            minRotation: 0
          }
        }]
      },
      pan: {
        enabled: false,
        mode: 'xy' // is panning about the y axis neccessary for bar charts?
      },
      zoom: {
        sensitivity:0.5, drag: false, enabled: true, mode: 'x'
      }
    }
});

这是我的代码工作:

https://jsfiddle.net/ogq5uex6/2/



1> Udara Kasun..:

@yavg请查看下面的截图.许多标签都是重复的.不要像这样添加重复的标签.尝试添加24小时的时间作为我的答案

在此输入图像描述

我想你会这样想的.

    var ctx = document.getElementById("canvas").getContext('2d');
    var myChart = new Chart(ctx, {
       type: 'bar',
       data: {
          labels:   
          ["08 Aug 2018 14:42","09 Aug 2018 11:24","04 Sep 2018 13:23","04 Sep 2018 13:26","04 Sep 2018 13:31","04 Sep 2018 13:33","04 Sep 2018 13:35","04 Sep 2018 13:36","04 Sep 2018 13:38","04 Sep 2018 13:39","04 Sep 2018 13:40","04 Sep 2018 13:45","04 Sep 2018 13:46","04 Sep 2018 13:49","04 Sep 2018 13:50","04 Sep 2018 13:51","04 Sep 2018 13:53","04 Sep 2018 14:07","04 Sep 2018 14:19","04 Sep 2018 14:20","04 Sep 2018 14:21","04 Sep 2018 14:30","04 Sep 2018 14:31","04 Sep 2018 14:33","05 Sep 2018 09:30","05 Sep 2018 09:31","08 Aug 2018 14:43","09 Aug 2018 11:25","04 Sep 2018 13:22","04 Sep 2018 13:27","04 Sep 2018 13:32","04 Sep 2018 13:34","04 Sep 2018 13:37","04 Sep 2018 13:41","04 Sep 2018 01:40","04 Sep 2018 01:41","04 Sep 2018 01:42","04 Sep 2018 01:45","04 Sep 2018 01:46","04 Sep 2018 01:49","04 Sep 2018 01:50","04 Sep 2018 01:51","04 Sep 2018 01:53","04 Sep 2018 02:07","04 Sep 2018 02:19","04 Sep 2018 02:20","04 Sep 2018 02:22","04 Sep 2018 02:36","04 Sep 2018 02:32","04 Sep 2018 02:35","05 Sep 2018 10:31","05 Sep 2018 10:32"],
          datasets: [{"label":"Estatura (cm)","backgroundColor":"rgba(0, 100, 150, 0.5)","pointBorderColor":"rgba(26,179,148,1)","data":["68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00","68.00","69.00","70.00","71.00","72.00","73.00","74.00","75.00","76.00","77.00","78.00","79.00","80.00","81.00","82.00","83.00","84.00","85.00","86.00","87.00","88.00","89.00","90.00","91.00"]}]
       },
        options: {
          legend: {
            position: 'top',
          },
          scales: {
            xAxes: [{
              ticks: {
                autoSkip: true,
                maxRotation: 0,
                minRotation: 0
              }
            }]
          },
          pan: {
            enabled: false,
            mode: 'xy' // is panning about the y axis neccessary for bar charts?
          },
          zoom: {
            sensitivity:0.5, drag: false, enabled: true, mode: 'x'
          }
        }
    });









推荐阅读
  • 本文介绍了如何通过掌握 IScroll 技巧来实现流畅的上拉加载和下拉刷新功能。首先,需要按正确的顺序引入相关文件:1. Zepto;2. iScroll.js;3. scroll-probe.js。此外,还提供了完整的代码示例,可在 GitHub 仓库中查看。通过这些步骤,开发者可以轻松实现高效、流畅的滚动效果,提升用户体验。 ... [详细]
  • 本文深入探讨了 MXOTDLL.dll 在 C# 环境中的应用与优化策略。针对近期公司从某生物技术供应商采购的指纹识别设备,该设备提供的 DLL 文件是用 C 语言编写的。为了更好地集成到现有的 C# 系统中,我们对原生的 C 语言 DLL 进行了封装,并利用 C# 的互操作性功能实现了高效调用。此外,文章还详细分析了在实际应用中可能遇到的性能瓶颈,并提出了一系列优化措施,以确保系统的稳定性和高效运行。 ... [详细]
  • 在单个图表中实现饼图与条形图的精准对齐 ... [详细]
  • Java服务问题快速定位与解决策略全面指南 ... [详细]
  • 深入解析 Django 中用户模型的自定义方法与技巧 ... [详细]
  • BZOJ4240 Gym 102082G:贪心算法与树状数组的综合应用
    BZOJ4240 Gym 102082G 题目 "有趣的家庭菜园" 结合了贪心算法和树状数组的应用,旨在解决在有限时间和内存限制下高效处理复杂数据结构的问题。通过巧妙地运用贪心策略和树状数组,该题目能够在 10 秒的时间限制和 256MB 的内存限制内,有效处理大量输入数据,实现高性能的解决方案。提交次数为 756 次,成功解决次数为 349 次,体现了该题目的挑战性和实际应用价值。 ... [详细]
  • 结语 | 《探索二进制世界:软件安全与逆向分析》读书笔记:深入理解二进制代码的逆向工程方法
    结语 | 《探索二进制世界:软件安全与逆向分析》读书笔记:深入理解二进制代码的逆向工程方法 ... [详细]
  • 如何将PHP文件上传至服务器及正确配置服务器地址 ... [详细]
  • 在 Android 开发中,通过合理利用系统通知服务,可以显著提升应用的用户交互体验。针对 Android 8.0 及以上版本,开发者需首先创建并注册通知渠道。本文将详细介绍如何在应用中实现这一功能,包括初始化通知管理器、创建通知渠道以及发送通知的具体步骤,帮助开发者更好地理解和应用这些技术细节。 ... [详细]
  • 本文深入探讨了 HTML 中的 `margin` 属性,详细解析了其基本特性和应用场景。文章不仅介绍了 `margin` 的基本概念,还重点讨论了垂直外边距合并现象,并分析了 `margin` 在块级元素与内联元素中的不同表现。通过实例和代码示例,帮助读者全面理解 `margin` 的使用技巧和常见问题。 ... [详细]
  • voc生成xml 代码
    目录 lxmlwindows安装 读取示例 可视化 生成示例 上面是代码,下面有调用示例 api调用代码,其实只有几行:这个生成代码也很简 ... [详细]
  • 本文介绍了使用 Python 编程语言高效抓取微博文本和动态网页图像数据的方法。通过详细的示例代码,展示了如何利用爬虫技术获取微博内容和动态图片,为数据采集和分析提供了实用的技术支持。对于对网络数据抓取感兴趣的读者,本文具有较高的参考价值。 ... [详细]
  • Spring框架入门指南:专为新手打造的详细学习笔记
    Spring框架是Java Web开发中广泛应用的轻量级应用框架,以其卓越的功能和出色的性能赢得了广大开发者的青睐。本文为初学者提供了详尽的学习指南,涵盖基础概念、核心组件及实际应用案例,帮助新手快速掌握Spring框架的核心技术与实践技巧。 ... [详细]
  • 本文探讨了在Android应用中实现动态滚动文本显示控件的优化方法。通过详细分析焦点管理机制,特别是通过设置返回值为`true`来确保焦点不会被其他控件抢占,从而提升滚动文本的流畅性和用户体验。具体实现中,对`MarqueeText.java`进行了代码层面的优化,增强了控件的稳定性和兼容性。 ... [详细]
  • 优化后的标题:校园互联新方案:10397连接教育未来 ... [详细]
author-avatar
2449978963潇潇
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有