Financial Charts

C1Chart implements two types of financial chart: Candle and HighLowOpenClose. Both are commonly used to display variations in stock prices over a period of time.

The difference between common chart types and financial charts is that Candle and HighLowOpenClose charts require a special type of data series object, the HighLowOpenCloseSeries. In this type of data series, each point corresponds to a period (typically one day) and contains five values:

      Time

      Price at the beginning of period (Open)

      Price at the end of period (Close)

      Minimum price during period (Low)

      Maximum price during period (High)

To create financial charts you need to provide all these values.

For example, if the values were provided by the application as collections, then you could use the code below to create the data series:

// create data series

HighLowOpenCloseSeries ds = new HighLowOpenCloseSeries();

ds.XValuesSource = dates; // dates are along x-axis

ds.OpenValuesSource = open;

ds.CloseValuesSource = close;

ds.HighValuesSource = hi;

ds.LowValuesSource = lo;

 

// add series to chart

chart.Data.Children.Add(ds);

 

// set chart type

chart.ChartType = isCandle

  ? ChartType.Candle

  : ChartType.HighLowOpenClose;

 

Another option is to use data-binding. For example, if the data is available as a collection of StockQuote objects such as:

public class Quote

{

  public DateTime Date { get; set; }

  public double Open { get; set; }

  public double Close { get; set; }

  public double High { get; set; }

  public double Low { get; set; }

}

 

Then the code that creates the data series would be as follows:

// create data series

HighLowOpenCloseSeries ds = new HighLowOpenCloseSeries();

 

// bind all five values

ds.XValueBinding = new Binding("Date"); // dates are along x-axis

ds.OpenValueBinding = new Binding("Open");

ds.CloseValueBinding = new Binding("Close");

ds.HighValueBinding = new Binding("High");

ds.LowValueBinding = new Binding("Low");

 

// add series to chart

chart.Data.Children.Add(ds);

 

// set chart type

chart.ChartType = isCandle

  ? ChartType.Candle

  : ChartType.HighLowOpenClose;


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.