Pre loader

Cursor Label Format for DateNumericAxis

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 am trying to change the format of CursorModifier

sciChartSurface.chartModifiers.add(
  new CursorModifier({
    modifierGroup: 'Chart',
    showAxisLabels: true,
    showTooltip: false,
    showYLine: false,
    showXLine: true,
  })
);

I have a custom DateLabelProvider for the xAxis that return dates in this format ‘MM/dd HH:mm’ but the CursorModifier tooltip is showing the ‘MM/dd/YYYY’ format, how can I change it?

Version
3.2.446
Images
  • You must to post comments
Best Answer
0
0

Hi there,

There should be some examples for this in the docs. Two things you need to know:

  1. The Cursor and Tooltip Label format is controlled by the axis
  2. The axis has properties and functions for label formatting and cursor / tooltip label formatting

Take a look at the page titled Formatting CursorModifier Tooltips

Basic CursorModifier Tooltip Formatting Options
Tooltip and Axis Label formatting comes from the axis.labelprovider.formatCursorLabel() function and is axis-specific. You can read more about the Axis.LabelProvider API here, including how to specify formats from Enums and override formatting programmatically.

Below we’re going to show you how to apply cursor formatting to enable four-decimal places on tooltips.

// Create a chart surface
  const { sciChartSurface, wasmContext } = await SciChartSurface.create(divElementId, {
    theme: new SciChartJsNavyTheme(),
    titleStyle: { fontSize: 16 }
  });
  
  sciChartSurface.xAxes.add(new NumericAxis(wasmContext, {
    // label format options applied to the X-Axis
    labelPrecision: 2,
    labelFormat: ENumericFormat.Decimal,
    // label format options applied to cursors & tooltips
    cursorLabelPrecision: 4,
    cursorLabelFormat: ENumericFormat.Decimal
  }));
  sciChartSurface.yAxes.add(new NumericAxis(wasmContext, {
    // label format options applied to the X-Axis
    labelPrecision: 1,
    labelFormat: ENumericFormat.Decimal,
    // label format options applied to cursors & tooltips
    cursorLabelPrecision: 4,
    cursorLabelFormat: ENumericFormat.Decimal
  }));
  
  // Add a CursorModifier to the chart
  const cursorModifier = new CursorModifier({
    showTooltip: true,
    showAxisLabels: true,
    hitTestRadius: 10,
  });
  sciChartSurface.chartModifiers.add(cursorModifier);
  

There’s a codepen in the Formatting CursorModifier Tooltips documentation page which you can modify & extend for date formatting.

For your specific example, if you already have a DateLabelProvider for the xAxis then you probably just need to override both formatLabel and formatCursorLabel.

There’s some further information and reading in the Axis documentation.

For example:

hope this helps!

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.