简体   繁体   English

LightningChart JS 中顶部、底部和右侧的填充

[英]Padding on top, bottom and right in LightningChart JS

Sometimes my line chart is at very bottom right of the screen which makes it little hard to read.有时我的折线图位于屏幕的右下角,这使得它有点难以阅读。 How can I set the padding around multiple line charts?如何围绕多个折线图设置填充?

I tried something like this but I get a max stack call size error:我尝试过这样的事情,但我得到一个最大堆栈调用大小错误:

// Bind X Axes together.
const HandleScaleChangeX = (chartIndex) => {
    return (start, end) => {
        for (let i = 0; i < charts.length; i++) {
            const axis = charts[i].getDefaultAxisX()
  
            if (end !== xVal) {
                axis.setInterval(start, xVal+50, false, true)
            }
        }
    }
}
for (let i = 0; i < charts.length; i++) {
    const chart = charts[i]
    chart.getDefaultAxisX()
         .onScaleChange(HandleScaleChangeX(i))
}

Whereas the following line, where xVal is the length of the chart, works fine:而下面的行,其中xVal是图表的长度,工作正常:

axis.setInterval(start, xVal, false, true) 

You are really close to achieving the code with padding on the right with fixed X end value.您真的很接近在右侧使用固定 X 结束值填充的代码。 You just need to change the if(end !== xVal) check to check if the end is same as xVal + padding , where padding is the amount you want to have as padding.您只需要更改if(end !== xVal)检查以检查end是否与xVal + padding相同,其中padding是您想要作为填充的数量。 Then when setting the new interval you can set the end value to be xVal + padding .然后在设置新间隔时,您可以将结束值设置为xVal + padding

let padding = 50
if (end !== xVal + padding) {
    axis.setInterval(start, xVal + padding, false, true)
}

On Y axis you want to control both of the start and end of the axis interval so the changes to interval in onScaleChange have to be aggregated to a single call to setInterval .在 Y 轴上,您希望同时控制轴间隔的开始和结束,因此onScaleChange中对间隔的更改必须汇总到对setInterval的单个调用中。 The applying of padding is done same way as on X axis just now with event attached to the Y axis.填充的应用与刚才在 X 轴上的方式相同,事件附加到 Y 轴。

const axisY = chart.getDefaultAxisY()
let yMaxVal = 15
let yMinVal = 0
axisY.onScaleChange((start, end) => {
    let newScaleStart = start
    let newScaleEnd = end
    let updateInterval = false

    if (end < yMaxVal + padding) {
        newScaleEnd = yMaxVal + padding
        updateInterval = true
    }
    if (start > yMinVal - padding) {
        newScaleStart = yMinVal - padding
        updateInterval = true
    }
    if (updateInterval) {
        axisY.setInterval(newScaleStart, newScaleEnd, false, true)
    }
})

If you would like to fix the Y start and end to a specific value you can just change the < and > comparisons when comparing the start and end to the padding value with !== comparison.如果您想将 Y 开始和结束固定为特定值,您可以在使用!==比较开始和结束与填充值进行比较时更改<>比较。

    if (start !== yMinVal - padding) {
        newScaleStart = yMinVal - padding
        updateInterval = true
    }

That would keep the Y axis minimum value on a fixed point with padding included.这将使 Y 轴最小值保持在包含填充的固定点上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM