private void Form1_Load(object sender, EventArgs e) { // Create a new chart. ChartControl stockChart = new ChartControl(); // Create a stock series. Series series1 = new Series("Series 1", ViewType.Stock); // Bind the series to data. series1.DataSource = GetDataPoints(); series1.SetFinancialDataMembers("Argument", "Low", "High", "Open", "Close"); // Specify that date-time arguments are expected. series1.ArgumentScaleType = ScaleType.DateTime; // Add the series to the chart. stockChart.Series.Add(series1); // Customize the series view settings. StockSeriesView view = (StockSeriesView)series1.View; view.LineThickness = 2; view.LevelLineLength = 0.25; // Specify the series reduction options. view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue; view.ReductionOptions.Level = StockLevel.Close; view.ReductionOptions.Visible = true; // Set point colors. view.Color = Color.Green; view.ReductionOptions.Color = Color.Red; // Access the chart's diagram. XYDiagram diagram = (XYDiagram)stockChart.Diagram; // Exclude empty ranges from the X-axis range // to avoid gaps in the chart's data. diagram.AxisX.DateTimeScaleOptions.SkipRangesWithoutPoints = true; // Hide the range without points at the beginning of the y-axis. diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false; // Hide the legend. stockChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; // Add a title to the chart. stockChart.Titles.Add(new ChartTitle()); stockChart.Titles[0].Text = "Stock Chart"; // Add the chart to the form. stockChart.Dock = DockStyle.Fill; this.Controls.Add(stockChart); }
private void Form1_Load(object sender, EventArgs e) { // Create an empty chart. ChartControl stockChart = new ChartControl(); // Create a stock series, add it to the chart and set its properties. Series series1 = new Series("Series 1", ViewType.Stock); stockChart.Series.Add(series1); series1.ArgumentScaleType = ScaleType.DateTime; series1.ValueScaleType = ScaleType.Numerical; // Add points to the series. series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 1), new object[] { 4.00, 5.00, 5.00, 4.85 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 2), new object[] { 6.05, 8.05, 6.05, 7.05 })); series1.Points.Add(new SeriesPoint(new DateTime(1994, 3, 3), new object[] { 6.25, 8.25, 6.75, 7.15 })); // Create and customize a trendline, TrendLine trendline1 = new TrendLine("A Trend"); trendline1.Point1.Argument = new DateTime(1994, 3, 1); trendline1.Point1.ValueLevel = ValueLevel.High; trendline1.Point2.Argument = new DateTime(1994, 3, 3); trendline1.Point2.ValueLevel = ValueLevel.High; trendline1.ExtrapolateToInfinity = false; trendline1.Color = Color.Red; trendline1.LineStyle.DashStyle = DashStyle.Dash; // Cast the view type of the series to the Stock view. StockSeriesView myView = ((StockSeriesView)series1.View); // Define the Y-axis range. myView.AxisY.WholeRange.AlwaysShowZeroLevel = false; // Add the trendline to the series collection of indicators. myView.Indicators.Add(trendline1); // Add the chart to the form. stockChart.Dock = DockStyle.Fill; this.Controls.Add(stockChart); }
Series CreateStockSeries() { Series s = new Series("Last", ViewType.Stock); s.ArgumentDataMember = "Time"; s.ArgumentScaleType = ScaleType.DateTime; s.ValueDataMembers.AddRange("Low", "High", "Open", "Close"); s.ValueScaleType = ScaleType.Numerical; StockSeriesView view = new StockSeriesView(); view.ShowOpenClose = StockType.Both; view.LineThickness = 2; view.LevelLineLength = 0.25; view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue; view.ReductionOptions.Level = StockLevel.Open; view.ReductionOptions.Visible = true; s.View = view; s.DataSource = Ticker.CandleStickData; return(s); }