Pre loader

Is it possible to create two xAxis, where one is normal and the other one is Horizontally Stacked Axis Layout?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
1
0

I want to create two xAxis, the first one will be a normal xAxis and the second one will be an array of date ranges, but the issue then is that since all the xAxis are inside one array together, they all are stacked on top of each other.

I tried sciChartSurface.layoutManager.bottomOuterAxesLayoutStrategy = new BottomAlignedOuterHorizontallyStackedAxisLayoutStrategy(); but that only create all xAxis into one line of xAxis.

I want two line of xAxis, where the first one is normal, but second xAxis should be Horizontally Stacked Axis Layout.

The first image is before horizontal stacked is applied and the second after.

The third image show the xAxes array from sciChartSurface.xAxes, the index(0) of the array is the first xAxis, which should be normal, and the rest (index 1 – 8) should be horizontally stacked.

The horizontal stacked xAxis should be right below the first xAxis.

Version
3.1.346
Images
  • You must to post comments
Best Answer
2
0

For the switched placement of normal and stacked axes:

You can just make update the layoutAxes method by changing the order in which you are applying the stacked/normal strategies and using an appropriate offset from the top.

The function before:

  // Override layoutAxes from the base class
  layoutAxes(left, top, right, bottom, axes) {
    const [firstAxis, ...stackedAxes] = axes;
    // layout first axis with the regular logic
    this.defaultBottomOuterAxisLayoutStrategy.layoutAxes(
      left, top, right, bottom, [firstAxis]
    );

    // after the layout phase we get axis.viewRect which specifies size and position of an axis
    // and then we can layout rest of the axes with stacked strategy beneath it.
    super.layoutAxes(left, firstAxis.viewRect.bottom, right, bottom, stackedAxes);
  }

results in this
enter image description here

The function after:

layoutAxes(left, top, right, bottom, axes) {
    const [firstAxis, ...stackedAxes] = axes;
    // layout stacked axes first
    super.layoutAxes(left, top, right, bottom, stackedAxes);

    // then get the top offset for the normalAxis with stackedAxis.viewRect.bottom
    const stackedAxis = stackedAxes[0]
    this.defaultBottomOuterAxisLayoutStrategy.layoutAxes(
        left,
        stackedAxis.viewRect.bottom,
        right,
        bottom,
        [firstAxis] // normal axis
    );
}

results in this

enter image description here

  • You must to post comments
Best Answer
1
0

Hello, here is an example of creating a custom Axis Layout Strategy by extending a strategy provided by the lib:

// Example of creating a custom layout manager. 
//
// Axis rendering  happens in 2 phases: measure & layout.
// Axis size and positioning is calculated by an axis layout strategy accordingly to the axisAlignment and isInner properties
// This custom Layout Strategy applies normal layout strategy to the first axis and the stacked strategy to the rest of bottom-aligned outer axes
class CustomAxisLayoutStrategy extends BottomAlignedOuterHorizontallyStackedAxisLayoutStrategy {

  constructor() {
    super();

    /** The strategy used for normal (non-stacked) layout */
    this.defaultBottomOuterAxisLayoutStrategy = new BottomAlignedOuterAxisLayoutStrategy();
  }

  // override measureAxes from the base class
  measureAxes(sciChartSurface,  chartLayoutState,  axes) {
    const [firstAxis, ...stackedAxes] = axes;
    // measure stacked axes and max height (stackedAreaSize) required by them
    super.measureAxes(sciChartSurface, chartLayoutState, stackedAxes);
    const stackedAreaSize = chartLayoutState.bottomOuterAreaSize;

    // measure first axis with the regular logic
    this.defaultBottomOuterAxisLayoutStrategy.measureAxes(
      sciChartSurface,
      chartLayoutState,
      [firstAxis]
    );

    // calculate height required by the first axis and then the total height
    const firstAxisSize = getHorizontalAxisRequiredSize(firstAxis.axisLayoutState);
    chartLayoutState.bottomOuterAreaSize = firstAxisSize + stackedAreaSize;
  }

  // Override layoutAxes from the base class
  layoutAxes(left, top, right, bottom, axes) {
    const [firstAxis, ...stackedAxes] = axes;
    // layout first axis with the regular logic
    this.defaultBottomOuterAxisLayoutStrategy.layoutAxes(
      left, top, right, bottom, [firstAxis]
    );

    // after the layout phase we get axis.viewRect which specifies size and position of an axis
    // and then we can layout rest of the axes with stacked strategy beneath it.
    super.layoutAxes(left, firstAxis.viewRect.bottom, right, bottom, stackedAxes);
  }
}

Full example setup in TypeScript: https://codesandbox.io/s/custom-axis-layout-strategy-7cs243?file=/src/index.ts

There is also a Codepen for JavaScript below here:
https://codepen.io/scichart/pen/wvQNQjx

enter image description here

Let us know if this works fine in your case or if you find any issues while using it.

  • You must to post comments
1
0

What should I do if I want to switch the placement of the stacked axes and normal axes?

For example, put the first xAxis at the bottom and put the stacked axes above it. What dictate the placement/layout?

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.