首页 > 其他分享 >Chartist.js折线图(四)

Chartist.js折线图(四)

时间:2024-04-26 14:22:06浏览次数:17  
标签:lineSmooth series chart js Date 折线图 new Chartist

线插值/平滑

  • 代码如下
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="./chartist.min.css">
    <script src="./chartist.min.js"></script>
  </head>
  <body>
    <div class="ct-chart ct-perfect-fourth" style="width: 500px;height: 350px;"></div>
    <script>
        var chart = new Chartist.Line('.ct-chart', {
        labels: [1, 2, 3, 4, 5],
        series: [
            [1, 5, 10, 0, 1],
            [10, 15, 0, 1, 2]
        ]
        }, {
        // Remove this configuration to see that chart rendered with cardinal spline interpolation
        // Sometimes, on large jumps in data values, it's better to use simple smoothing.
        lineSmooth: Chartist.Interpolation.simple({
            divisor: 2
        }),
        fullWidth: true,
        chartPadding: {
            right: 20
        },
        low: 0
        });

    </script>
  </body>
</html>
  • 效果图
点击查看详情

系列覆盖

  • 代码如下
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="./chartist.min.css">
    <script src="./chartist.min.js"></script>
  </head>
  <body>
    <div class="ct-chart ct-perfect-fourth" style="width: 500px;height: 350px;"></div>
    <script>
        var chart = new Chartist.Line('.ct-chart', {
        labels: ['1', '2', '3', '4', '5', '6', '7', '8'],
        // Naming the series with the series object array notation
        series: [{
            name: 'series-1',
            data: [5, 2, -4, 2, 0, -2, 5, -3]
        }, {
            name: 'series-2',
            data: [4, 3, 5, 3, 1, 3, 6, 4]
        }, {
            name: 'series-3',
            data: [2, 4, 3, 1, 4, 5, 3, 2]
        }]
        }, {
        fullWidth: true,
        // Within the series options you can use the series names
        // to specify configuration that will only be used for the
        // specific series.
        series: {
            'series-1': {
            lineSmooth: Chartist.Interpolation.step()
            },
            'series-2': {
            lineSmooth: Chartist.Interpolation.simple(),
            showArea: true
            },
            'series-3': {
            showPoint: false
            }
        }
        }, [
        // You can even use responsive configuration overrides to
        // customize your series configuration even further!
        ['screen and (max-width: 320px)', {
            series: {
            'series-1': {
                lineSmooth: Chartist.Interpolation.none()
            },
            'series-2': {
                lineSmooth: Chartist.Interpolation.none(),
                showArea: false
            },
            'series-3': {
                lineSmooth: Chartist.Interpolation.none(),
                showPoint: true
            }
            }
        }]
        ]);

    </script>
  </body>
</html>
  • 效果图
点击查看详情

时间序列

  • 代码案例
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="./chartist.min.css">
    <script src="./chartist.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
  </head>
  <body>
    <div class="ct-chart ct-perfect-fourth" style="width: 500px;height: 350px;"></div>
    <script>
        // Requires Moment.js

        var chart = new Chartist.Line('.ct-chart', {
        series: [
            {
            name: 'series-1',
            data: [
                {x: new Date(143134652600), y: 53},
                {x: new Date(143234652600), y: 40},
                {x: new Date(143340052600), y: 45},
                {x: new Date(143366652600), y: 40},
                {x: new Date(143410652600), y: 20},
                {x: new Date(143508652600), y: 32},
                {x: new Date(143569652600), y: 18},
                {x: new Date(143579652600), y: 11}
            ]
            },
            {
            name: 'series-2',
            data: [
                {x: new Date(143134652600), y: 53},
                {x: new Date(143234652600), y: 35},
                {x: new Date(143334652600), y: 30},
                {x: new Date(143384652600), y: 30},
                {x: new Date(143568652600), y: 10}
            ]
            }
        ]
        }, {
        axisX: {
            type: Chartist.FixedScaleAxis,
            divisor: 5,
            labelInterpolationFnc: function(value) {
            return moment(value).format('MMM D');
            }
        }
        });
    </script>
  </body>
</html>
  • 效果图
点击查看详情

标签:lineSmooth,series,chart,js,Date,折线图,new,Chartist
From: https://www.cnblogs.com/dogleftover/p/18159983

相关文章

  • js使用xlsx读取excel文件
    官方案例:https://oss.sheetjs.com/sheetjs/参考:https://www.jb51.net/javascript/293098ilx.htm大致的代码如下,如果要实际使用还得修改修改完善完善。<inputtype="file"id="uploadExcel"multiple onChange=’onImportExcel'/>onImportExcel=file=>{//......
  • 《Vue.js设计与实现》 第八章 挂载与更新
    8.1挂载子节点和元素的属性8.2HTMLAttributes与DOMProperties8.3正确地设置元素属性8.4class的处理8.5卸载操作8.6区分vnode的类型8.7事件的处理8.8事件冒泡与更新时机问题8.9更新子节点8.10文本节点和注释节点8.11Fragment......
  • js的函数及无参与有参构造函数
    1.函数定义fuctionfn(str){//1.定义函数alert(str);}fn("测试方法");varfn1=function(str){//2.定义函数alert(str);}varfn2=fuction(f,str){f(str);}fn2(fn1,"方法作为参数");//函数可以作为方法传递参数2.无参构造:varperson=function(){alert("......
  • golang之json.RawMessage
    RawMessage具体来讲是json库中定义的一个类型。它实现了Marshaler接口以及Unmarshaler接口,以此来支持序列化的能力。注意上面我们引用 官方doc 的说明。 使用场景设想一下,我们给某种业务场景定义了一个通用的model,其中部分数据需要在不同场景下对应不同的结构体......
  • js 闭包的概念及应用场景
    1.概念是内部函数可以访问外部函数作用域中的变量。2.来由由于JavaScript中的函数作用域规则和函数可以作为值传递的特性产生的3.优点封装性(可以将变量和函数封装起来,防止外部访问和修改,提高了代码的可维护性和可重用性)保存状态(即使函数已经执行完毕,状态仍然保存,在事件处理......
  • Chartist.js折线图(三)
    事件替换图形代码如下<!DOCTYPEhtml><html><head><linkrel="stylesheet"href="./chartist.min.css"><scriptsrc="./chartist.min.js"></script></head><body><div......
  • Chartist.js折线图(二)
    折线散点图代码如下<!DOCTYPEhtml><html><head><linkrel="stylesheet"href="./chartist.min.css"><scriptsrc="./chartist.min.js"></script></head><body><divc......
  • Chartist.js折线图
    数据漏洞代码案例<!DOCTYPEhtml><html><head><linkrel="stylesheet"href="./chartist.min.css"><scriptsrc="./chartist.min.js"></script></head><body><divcl......
  • Js链式调用面试题
    Js链式调用需求:要求可以链式调用对象的方法,该对象有四个方法,加减乘除,一个get结果方法eg:counter.add(3).sub(1).get()//2方法一通过Es6实现classCounter{privateresult=0;add(val:number){this.result+=val;returnthis;}sub(val:nu......
  • vue3+vite+js 引用public文件夹中js文件
    vue的public的资源在打包时不会被编译,只会copy所以在在src路径下引入public文件夹下的图片、视频、音频,编译不会改变其路径,但是在src下引入public文件夹下的js、json,在打包时都会被编译,所以直接引入会丢失路径(因为打包时,当前页面引入的路径被hash打包,而public文件夹下只是被cop......