This section provides step-by-step instructions for building a Candle Chart. The graph shows the information as a candle chart with four Y variables on the y-axis that represent the hi, low, open, and close values of the stock and the x-axis values provide the position for each candle.
The following chart illustration is shown before you begin creating the chart:
Both steps are shown below for creating the Candle chart at design time or programmatically through the Chart objects.
To create a candle chart at design time
This topic walks you through the steps for creating a candle chart using the Chart Properties designer. In this topic you will learn how to set the specific chart type, modify the data series, add data to the chart, and format the appearance of the candle all at design-time in a few simple steps.
The first step in configuring a chart through the smart tag Chart Properties is to select a gallery type from the wealth of chart types available. From basic chart types like Bar and Lines to more complex charts like Polar and Surface, C1Chart allows you to deal with any data visualization needed.
Click Remove to remove Series0, Series 1, Series 2, and Series 3.
Next we will change the default line color to red, increase the body width of the candle, and increase the line thickness. We will use the LineStyle property to change the color of the lines to red, the SymbolStyle property to change the body width of the candle, and LineStyle property to change the thickness of the lines.
The body of the candle increase from its default size, 5, to 10.
To create a candle chart programmatically
A Candle chart can be created programmatically using the following steps:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Imports C1.Win.C1Chart |
To write code in C#
C# |
Copy Code
|
---|---|
using C1.Win.C1Chart; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) c1Chart1.ChartGroups(0).ChartData.SeriesList.AddNewSeries() 'Declare the x and y variables as double to represent the x, y, y1, y2, and y3 values and assign the values Dim x As Double() = New Double() {1, 2, 3, 4, 5} Dim y_hi As Double() = New Double() {8, 12, 10, 12, 15} Dim y_low As Double() = New Double() {20, 22, 19, 24, 25} Dim y_open As Double() = New Double() {10, 16, 17, 15, 23} Dim y_close As Double() = New Double() {16, 19, 15, 22, 18} 'copy the x, y, y1, y2, and y3 data into the chart group c1Chart1.ChartGroups(0).ChartData(0).X.CopyDataIn(x) c1Chart1.ChartGroups(0).ChartData(0).Y.CopyDataIn(y_hi) c1Chart1.ChartGroups(0).ChartData(0).Y1.CopyDataIn(y_low) c1Chart1.ChartGroups(0).ChartData(0).Y2.CopyDataIn(y_open) c1Chart1.ChartGroups(0).ChartData(0).Y3.CopyDataIn(y_close) 'assign the candle chart to the chart type c1Chart1.ChartGroups(0).ChartType = C1.Win.C1Chart.Chart2DTypeEnum.Candle 'Make the rising candles transparent to show rising prices c1Chart1.ChartGroups(0).HiLoData.FillTransparent = True 'Declare the color for the lines c1Chart1.ChartGroups(0).ChartData.SeriesList(0).LineStyle.Color = System.Drawing.Color.Red 'Increase the line thickness c1Chart1.ChartGroups(0).ChartData.SeriesList(0).LineStyle.Thickness = 2 'Increase the body width of the candle c1Chart1.ChartGroups(0).ChartData.SeriesList(0).SymbolStyle.Size = 10 End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void Form1_Load(object sender, EventArgs e) { c1Chart1.ChartGroups[0].ChartData.SeriesList.AddNewSeries(); //Declare the x and y variables as double to represent the x, y, y1, y2, and y3 values and assign the values double[] x = new double[] { 1, 2, 3, 4, 5 }; double[] y_hi = new double[] { 8, 12, 10, 12, 15 }; double[] y_low = new double[] { 20, 22, 19, 24, 25 }; double[] y_open = new double[] { 10, 16, 17, 15, 23 }; double[] y_close = new double[] { 16, 19, 15, 22, 18 }; //copy the x, y, y1, y2, and y3 data into the chart group c1Chart1.ChartGroups[0].ChartData[0].X.CopyDataIn(x); c1Chart1.ChartGroups[0].ChartData[0].Y.CopyDataIn(y_hi); c1Chart1.ChartGroups[0].ChartData[0].Y1.CopyDataIn(y_low); c1Chart1.ChartGroups[0].ChartData[0].Y2.CopyDataIn(y_open); c1Chart1.ChartGroups[0].ChartData[0].Y3.CopyDataIn(y_close); //assign the candle chart to the chart type c1Chart1.ChartGroups[0].ChartType = C1.Win.C1Chart.Chart2DTypeEnum.Candle; //Make the rising candles transparent to show rising prices c1Chart1.ChartGroups[0].HiLoData.FillTransparent = true; //Declare the color for the lines c1Chart1.ChartGroups[0].ChartData.SeriesList[0].LineStyle.Color = System.Drawing.Color.Red; //Increase the line thickness c1Chart1.ChartGroups[0].ChartData.SeriesList[0].LineStyle.Thickness = 2; c1Chart1.ChartGroups[0].ChartData.SeriesList[0].SymbolStyle.Size = 10; } |