在Lightningchart中,如何锁定2个或更多轴的Y轴,以使零始终保持同步



我需要在同一2D图(Lightningchart.viewxy)上显示电压和电流。为了将值保持在明显的比例,我使用了2个不同的轴。但是我和我的客户想确保零在两个不同的轴之间始终保持一致。这是可能的,如果是,我该怎么做?

感谢埃里克(Eric)提出的。图表和轴有事件来帮助您自定义这样的案件。至于记住,在同一水平位置上没有几个Yaxes的属性,例如缩放,放置事件手柄和修改轴的范围。下面是如何将两个轴(同一段)的参考值固定到图形区域中间的示例。

    private void ViewXY_Zoomed(object sender, Arction.Wpf.Charting.Views.ViewXY.ZoomedXYEventArgs e)
    {
        AxisY axis0 = _chart.ViewXY.YAxes[0];
        AxisY axis1 = _chart.ViewXY.YAxes[1];
        // get segment top & bottom coordinates [PX]
        GraphSegmentInfo gsi = _chart.ViewXY.GetGraphSegmentInfo();
        float fTop = gsi.SegmentTops[0];
        float fBottom = gsi.SegmentBottoms[0];
        int iScreenCoordForRefValue = (int)(fTop + fBottom) / 2;
        float fAxis0RefValue = 50, fAxis1RefValue = 0;
        double dAxis0ValueAtCoord, dAxis1ValueAtCoord;
        axis0.CoordToValue(iScreenCoordForRefValue, out dAxis0ValueAtCoord, false);
        axis1.CoordToValue(iScreenCoordForRefValue, out dAxis1ValueAtCoord, false);
        // pan Axis' RefValue position at RefScreenCoord
        double dNewMinAxis0 = axis0.Minimum - (dAxis0ValueAtCoord - fAxis0RefValue);
        double dNewMaxAxis0 = axis0.Maximum - (dAxis0ValueAtCoord - fAxis0RefValue);
        double dNewMinAxis1 = axis1.Minimum - (dAxis1ValueAtCoord - fAxis1RefValue);
        double dNewMaxAxis1 = axis1.Maximum - (dAxis1ValueAtCoord - fAxis1RefValue);
        _chart.BeginUpdate();
        axis0.SetRange(dNewMinAxis0, dNewMaxAxis0);
        axis1.SetRange(dNewMinAxis1, dNewMaxAxis1);
        _chart.EndUpdate();
    }
function alignChartHorizontally(chart) {
    chart.getDefaultAxisY().setThickness({
        min: 60
    })
}
if(yourFirstChart.show) alignChartHorizontally(yourFirstChart)
if(yourSecondChart.show) alignChartHorizontally(yourSeconcChart) 

// Synchronize all X Axes.
let isAxisXScaleChangeActive = false
const syncAxisXEventHandler = (axis, start, end) => {
   if (isAxisXScaleChangeActive) return
   isAxisXScaleChangeActive = true
   // Find all other X Axes.
   const otherAxes = allCharts
      .map(chart => chart.getDefaultAxisX())
      .filter(axis2 => axis2 !== axis)
   // Sync other X Axis intervals.  
   otherAxes.forEach((axis) => axis
      .setInterval(start, end, false, true)
   )
   isAxisXScaleChangeActive = false
}
//add both (or all) of your charts to this array:
allCharts = [myChart1, myChart2]
//adds event listener and handler to all your charts' scaleChange event emitters
allCharts.forEach(chart => chart.getDefaultAxisX().onScaleChange((start, end) => syncAxisXEventHandler(chart.getDefaultAxisX(), start, end)))

改编自:https://github.com/arction/lcjs-showcase-trading/blob/master/src/src/app.ts

相关内容

  • 没有找到相关文章

最新更新