Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

chart.js - Multiple line types in ChartJS

I have a project to recreate a Parametric EQ and am using Angular and Chartjs (angular-chart) to do so. Most of it's working, but, I have a need for two different line types in the same graph. Most of the filter types have lines connecting the points, but one of the filter types (band stop) should show a gap at the frequency. I can plot the X/Y of the points, but how do I get the span gaps to only apply to the one data set (and not the other 9)?

Thank you for your help!

    //I think the relevant data:
$scope.data = [
            [{x:-100,y:-90},{x:-60,y:-10},{x:-50,y:0}],
            [{x:-100,y:-80},{x:-50,y:-20},{x:0,y:0}],
            [{x:-100,y:-70},{x:-40,y:-30},{x:0,y:0}],
            [{x:-100,y:-60},{x:-30,y:-40},{x:0,y:0}],
            [{x:-100,y:-50},{x:-20,y:-50},{x:0,y:0}],
            [{x:-100,y:-40},{x:-30,y:-60},{x:0,y:0}],
            [{x:-100,y:-30},{x:-40,y:-70},{x:0,y:0}],
            [{x:-100,y:-20},{x:-50,y:-80},{x:0,y:0}],
            [{x:-100,y:-10},{x:-60,y:-90},{x:0,y:0}],
            [{x:-100,y:0},{x:-70,y:-100},{x:0,y:0}]


        ];
        $scope.options = {
            tooltips:{enabled:false},
            elements:{
                point:{
                    radius:0
                },
                line:{
                    tension:.25,
                    fill:false
                }
            },
            scales: {
                xAxes:[{
                    type:'logarithmic',
                    display:true,
                    ticks:{
                        min:10,
                        max:10000,
                        callback: function(...args) {
                            const value = Chart.Ticks.formatters.logarithmic.call(this, ...args);
                            if (value.length) {
                                return Number(value).toLocaleString()
                            }
                            return value;
                        }
                    },

                }],
                yAxes: [
                    {
                        id: 'y-axis-1',
                        ticks:{min:-20,max:20,stepSize:10},
                        type: 'linear',
                        display: true,
                        position: 'left'
                    }
                ]

            }
        };
question from:https://stackoverflow.com/questions/65621755/multiple-line-types-in-chartjs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Seems like you can add it in the specific dataset as an option in which you want it: https://www.chartjs.org/docs/latest/charts/line.html?h=spangaps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...