> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# GetXByTime()

## Definition

Returns the chart-canvas x-coordinate of the slot index of the primary **Bars** object corresponding to a specified time.

Since the time correlates with a specific bar index, and since bars move on the chart canvas as new bars are painted, the value returned by **GetXByTime()** can be expected to change as new bars are painted on the chart, or as the chart is scrolled backward or forward on the x-axis.

## Method Return Value

An int representing a chart-canvas x-coordinate.

## Syntax

`\<chartcontrol\>.GetXByTime(DateTime time)`

## Method Parameters

| Parameter | Description                                             |
| --------- | ------------------------------------------------------- |
| time      | A **DateTime** object used to determine an x-coordinate |

## Examples

```csharp
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
   DateTime timeToCheck = new DateTime(2017, 8, 6, 11, 0, 0);

   // Find the chart-canvas x-coordinate of the bar at the specified time
    int xCoordinate = chartControl.GetXByTime(timeToCheck);

   // Print the x-coordinate value
   Print(xCoordinate);
}
```