Chart


Summary

Represents the Chart Interface.

Syntax

public interface Chart : ChartArea

Members

NameTypeSummary
Activated Event
AddHotkey Method
Bars PropertyGets the chart Bar objects.
BarsTotal PropertyGets the total number of the bars on the chart.
ChartType PropertyGets or sets the type of the chart - Bar, Candlesticks, Line or Dots chart.
ChartTypeChanged EventOccurs when the chart type changes.
ColorsChanged EventOccurs when the chart color settings change.
ColorSettings PropertyGets the chart color settings.
Deactivated Event
DisplaySettings PropertyGets the chart display settings.
DisplaySettingsChanged EventOccurs when one or several charts display settings change.
FirstVisibleBarIndex PropertyGets the index of the first visible bar on the chart.
IndicatorAreaAdded EventOccurs when the indicator area is added.
IndicatorAreaRemoved EventOccurs when the indicator area is removed.
IndicatorAreas PropertyGets the read only list of the indicator areas.
IsActive Property
IsScrollingEnabled PropertyGets or sets the value indicating whether the scrolling is enabled or disabled for the chart. If disabled, then the
chart is not affected by scrolling, dragging, scaling, or pressing any keyboard keys, but is still affected by
resizing, zooming, and API calls for changing X or Y-axis positions on the chart.
KeyDown Event
LastVisibleBarIndex PropertyGets the index of the last visible bar on the chart.
MaxVisibleBars PropertyGets the maximum number of the visible bars on the chart.
ResetBarColor MethodResets the color of the bar to the default.
ResetBarColors MethodResets the colors of all the bars.
ResetTickVolumeColor MethodResets the color of the tick volume line to the default at the specified bar index.
ResetTickVolumeColors MethodResets the color of all the tick volume bars.
ScrollXBy MethodScrolls the chart by the X-axis for the specified number of bars.
ScrollXTo MethodScrolls the chart by the X-axis to the bar with the specified index.
SetBarColor MethodSets the color of the bar at the specified bar index. It will change the bar fill color and the outline color.
SetBarFillColor MethodSets the fill color of the bar at the specified bar index.
SetBarOutlineColor MethodSets the outline color of the bar at the specified bar index.
SetTickVolumeColor MethodSets the color of tick volume line at the specified bar index.
Symbol PropertyGets the chart symbol.
SymbolName PropertyGets the symbol name.
TimeFrame PropertyGets the time frame of the chart from 1 minute to 1 month.
TryChangeTimeFrame MethodChanges the time frame on the chart.
TryChangeTimeFrameAndSymbol MethodChanges the time frame and the symbol on the chart.
ZoomChanged EventOccurs when the chart zoom options change.
ZoomLevel PropertyGets or sets the zoom percent values. Valid values are from 5 to 500 with a step of 5, as can be seen on UI in the
charts Zoom control.

Example 1

using cAlgo.API;
namespace cAlgo
{
    // This sample indicator display's the chart data by using the current Chart object
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ChartSample : Indicator
    {
        private Grid _grid;
        private TextBlock _mouseLocationTextBlock;
        private TextBlock _mouseWheelDeltaTextBlock;
        private TextBlock _objectsNumberTextBlock;
        protected override void Initialize()
        {
            Chart.ChartTypeChanged += args => CreateAndAddGridToChart();
            Chart.ColorsChanged += args => CreateAndAddGridToChart();
            Chart.DisplaySettingsChanged += args => CreateAndAddGridToChart();
            Chart.Drag += args => CreateAndAddGridToChart();
            Chart.DragEnd += args => CreateAndAddGridToChart();
            Chart.DragStart += args => CreateAndAddGridToChart();
            Chart.IndicatorAreaAdded += args => CreateAndAddGridToChart();
            Chart.IndicatorAreaRemoved += args => CreateAndAddGridToChart();
            Chart.MouseMove += args =>
            {
                if (_mouseLocationTextBlock == null)
                    return;
                _mouseLocationTextBlock.Text = string.Format("({0}, {1})", args.MouseX, args.MouseY);
            };
            Chart.MouseLeave += args =>
            {
                if (_mouseLocationTextBlock == null)
                    return;
                _mouseLocationTextBlock.Text = "(Null, Null)";
                _mouseWheelDeltaTextBlock.Text = "0";
            };
            Chart.MouseWheel += args =>
            {
                if (_mouseWheelDeltaTextBlock == null)
                    return;
                _mouseWheelDeltaTextBlock.Text = args.Delta.ToString();
            };
            Chart.ObjectsAdded += args => _objectsNumberTextBlock.Text = Chart.Objects.Count.ToString();
            Chart.ObjectsRemoved += args => _objectsNumberTextBlock.Text = Chart.Objects.Count.ToString();
            Chart.ZoomChanged += args => CreateAndAddGridToChart();
            CreateAndAddGridToChart();
        }
        public override void Calculate(int index)
        {
        }
        private void CreateAndAddGridToChart()
        {
            if (_grid != null)
                Chart.RemoveControl(_grid);
            _grid = new Grid(10, 2)
            {
                BackgroundColor = Color.Gold,
                Opacity = 0.6,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Bottom
            };
            var style = new Style();
            style.Set(ControlProperty.Margin, 5);
            style.Set(ControlProperty.FontWeight, FontWeight.ExtraBold);
            style.Set(ControlProperty.ForegroundColor, Color.Red);
            _grid.AddChild(new TextBlock
            {
                Text = "Height",
                Style = style
            }, 0, 0);
            _grid.AddChild(new TextBlock
            {
                Text = Chart.Height.ToString(),
                Style = style
            }, 0, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Width",
                Style = style
            }, 1, 0);
            _grid.AddChild(new TextBlock
            {
                Text = Chart.Width.ToString(),
                Style = style
            }, 1, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Zoom Level",
                Style = style
            }, 2, 0);
            _grid.AddChild(new TextBlock
            {
                Text = Chart.ZoomLevel.ToString(),
                Style = style
            }, 2, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Objects #",
                Style = style
            }, 3, 0);
            _objectsNumberTextBlock = new TextBlock
            {
                Style = style,
                Text = Chart.Objects.Count.ToString()
            };
            _grid.AddChild(_objectsNumberTextBlock, 3, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Top Y",
                Style = style
            }, 4, 0);
            _grid.AddChild(new TextBlock
            {
                Text = Chart.TopY.ToString(),
                Style = style
            }, 4, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Bottom Y",
                Style = style
            }, 5, 0);
            _grid.AddChild(new TextBlock
            {
                Text = Chart.BottomY.ToString(),
                Style = style
            }, 5, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Type",
                Style = style
            }, 6, 0);
            _grid.AddChild(new TextBlock
            {
                Text = Chart.ChartType.ToString(),
                Style = style
            }, 6, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Mouse Location",
                Style = style
            }, 7, 0);
            _mouseLocationTextBlock = new TextBlock
            {
                Style = style,
                Text = "(Null, Null)"
            };
            _grid.AddChild(_mouseLocationTextBlock, 7, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Indicator Areas #",
                Style = style
            }, 8, 0);
            _grid.AddChild(new TextBlock
            {
                Text = Chart.IndicatorAreas.Count.ToString(),
                Style = style
            }, 8, 1);
            _grid.AddChild(new TextBlock
            {
                Text = "Mouse Wheel Delta",
                Style = style
            }, 9, 0);
            _mouseWheelDeltaTextBlock = new TextBlock
            {
                Style = style,
                Text = "0"
            };
            _grid.AddChild(_mouseWheelDeltaTextBlock, 9, 1);
            Chart.AddControl(_grid);
        }
    }
}
Reference