public void Plot(IProtocolChartData dataToPlot) { Clear(); chart.DataSource = dataToPlot.DataTable; chart.SeriesDataMember = dataToPlot.GroupingName; chart.InitializeColor(); // Specify the date-time argument scale type for the series, // as it is qualitative, by default. chart.SeriesTemplate.ArgumentScaleType = ScaleType.Numerical; chart.SeriesTemplate.ArgumentDataMember = dataToPlot.XValue; chart.SeriesTemplate.ValueScaleType = ScaleType.Numerical; chart.SeriesTemplate.ValueDataMembers.AddRange(dataToPlot.YValue); chart.SeriesTemplate.LabelsVisibility = DefaultBoolean.False; var stackedBarSeriesView = new StackedBarSeriesView {BarWidth = BarWidth}; chart.SeriesTemplate.View = stackedBarSeriesView; var diagram = (XYDiagram) chart.Diagram; ////// Access the type-specific options of the diagram. diagram.AxisX.Title.Text = XAxisTitle; diagram.AxisX.Title.Visibility = DefaultBoolean.True; diagram.AxisY.Title.Text = YAxisTitle; diagram.AxisY.Title.Visibility = DefaultBoolean.True; diagram.AxisX.WholeRange.Auto = true; diagram.AxisX.WholeRange.SetMinMaxValues(dataToPlot.XMin - BarWidth, dataToPlot.XMax + BarWidth); chart.Legend.LegendPosition(LegendPositions.RightInside); diagram.SecondaryAxesY.Clear(); SecondaryAxisY axisY2 = null; if (dataToPlot.NeedsMultipleAxis) { axisY2 = new SecondaryAxisY("Y2"); diagram.SecondaryAxesY.Add(axisY2); axisY2.Title.Text = Y2AxisTitle; axisY2.Title.Visibility = DefaultBoolean.True; } foreach (Series series in chart.Series) { var view = (BarSeriesView) series.View; if (dataToPlot.NeedsMultipleAxis) { if (dataToPlot.SeriesShouldBeOnSecondAxis(series.Name)) view.AxisY = axisY2; } series.Visible = true; } }
private void InitChart() { var template = chartControl.SeriesTemplate; template.SeriesDataMember = "Company"; template.SetDataMembers("Category", "Value"); StackedBarSeriesView view = new StackedBarSeriesView(); view.FillStyle.FillMode = FillMode.Solid; template.View = view; chartControl.DataSource = VM.TotalIncome; chartControl.OptionsPrint.SizeMode = PrintSizeMode.Zoom; chartControl.ObjectHotTracked += this.OnChartObjectHotTracked; chartControl.MouseUp += this.OnChartControlMouseUp; }
private void Form1_Load(object sender, EventArgs e) { // Create a chart and add it to the form: ChartControl chart = new ChartControl(); chart.Dock = DockStyle.Fill; this.Controls.Add(chart); // Bind the chart to a data source: chart.DataSource = DataPoint.GetDataPoints(); chart.SeriesTemplate.ChangeView(ViewType.StackedBar); chart.SeriesTemplate.SeriesDataMember = "Company"; chart.SeriesTemplate.SetDataMembers("Product", "Income"); // Enable series point labels, specify their text pattern and position: chart.SeriesTemplate.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True; chart.SeriesTemplate.Label.TextPattern = "${V}M"; ((BarSeriesLabel)chart.SeriesTemplate.Label).Position = BarSeriesLabelPosition.Center; // Customize series view settings (for example, bar width): StackedBarSeriesView view = (StackedBarSeriesView)chart.SeriesTemplate.View; view.BarWidth = 0.8; // Disable minor tickmarks on the x-axis: XYDiagram diagram = (XYDiagram)chart.Diagram; diagram.AxisX.Tickmarks.MinorVisible = false; // Add a chart title: chart.Titles.Add(new ChartTitle { Text = "Sales by Products" }); // Specify legend settings: chart.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker; chart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center; chart.Legend.AlignmentVertical = LegendAlignmentVertical.TopOutside; }
private void ConfigureIndicatorCharts(ChartSettings chartSettings) { var indicatorSeriesSettingsSet = new List <IndicatorSeriesColorSettings>(); var indicatorAddtionalPanels = IndicatorPanelSettings.GetAdditionalPanelsSettings(chartSettings.Period); //Build Series var viewSettingsByIndicatorType = IndicatorSeriesViewSettings.GetIndicatorSeriesViewSettings(chartSettings) .GroupBy(viewSettings => new { viewSettings.IndicatorType, viewSettings.CandlePeriod }); foreach (var seriesViewSettings in viewSettingsByIndicatorType) { var indicatorSerieses = new List <Series>(); var seriesViews = new List <SeriesViewColorEachSupportBase>(); foreach (var viewSettings in seriesViewSettings) { SeriesViewColorEachSupportBase seriesView; switch (viewSettings.ViewType) { case ViewType.Line: seriesView = new LineSeriesView(); break; case ViewType.Bar: seriesView = new StackedBarSeriesView(); break; case ViewType.Point: seriesView = new PointSeriesView(); break; default: throw new ArgumentOutOfRangeException(nameof(viewSettings.ViewType)); } var seriesSettings = new IndicatorSeriesColorSettings { IndicatorType = seriesViewSettings.Key.IndicatorType, CandlePeriod = seriesViewSettings.Key.CandlePeriod, }; var availableColors = IndicatorSeriesColorSettings.AvailableSeriesColors .Where(color => indicatorSeriesSettingsSet .Where(s => s.IndicatorType == seriesViewSettings.Key.IndicatorType && s.CandlePeriod == seriesViewSettings.Key.CandlePeriod) .All(s => s.SeriesColor != color)) .ToList(); seriesSettings.SeriesColor = availableColors.Any() ? availableColors.First() : IndicatorSeriesColorSettings.LastDefaultColor; indicatorSeriesSettingsSet.Add(seriesSettings); seriesView.Color = seriesSettings.SeriesColor; seriesViews.Add(seriesView); var indicatorSeries = new Series(viewSettings.IndicatorValue, viewSettings.ViewType); indicatorSeries.ArgumentScaleType = ScaleType.DateTime; indicatorSeries.LabelsVisibility = DevExpress.Utils.DefaultBoolean.False; indicatorSeries.ArgumentDataMember = "Moment"; indicatorSeries.ValueDataMembers.AddRange(viewSettings.IndicatorValue); indicatorSeries.View = seriesView; indicatorSerieses.Add(indicatorSeries); } var panelSettings = indicatorAddtionalPanels.FirstOrDefault(s => s.AssignedIndicators.Any(tuple => tuple.Item1 == seriesViewSettings.Key.IndicatorType && tuple.Item2 == seriesViewSettings.Key.CandlePeriod)); if (panelSettings != null) { if (panelSettings.Panel == null || panelSettings.AxisY == null) { var pane = new XYDiagramPane(); ((XYDiagram)chartControl.Diagram).Panes.Add(pane); panelSettings.Panel = pane; var axisY = new SecondaryAxisY(); ((XYDiagram)chartControl.Diagram).SecondaryAxesY.Add(axisY); panelSettings.AxisY = axisY; } foreach (var seriesView in seriesViews) { seriesView.Pane = panelSettings.Panel; seriesView.AxisY = panelSettings.AxisY; } } else { foreach (var seriesView in seriesViews) { seriesView.Pane = ((XYDiagram)chartControl.Diagram).DefaultPane; seriesView.AxisY = ((XYDiagram)chartControl.Diagram).AxisY; } } chartControl.Series.AddRange(indicatorSerieses.ToArray()); } }