private static void synchronizeAxis(SecondaryAxisX secondaryAxisX, AxisX axisX)
 {
     secondaryAxisX.WholeRange.MinValue         = axisX.WholeRange.MinValue;
     secondaryAxisX.WholeRange.MaxValue         = axisX.WholeRange.MaxValue;
     secondaryAxisX.WholeRange.AutoSideMargins  = axisX.WholeRange.AutoSideMargins;
     secondaryAxisX.WholeRange.SideMarginsValue = axisX.WholeRange.SideMarginsValue;
 }
        private XYDiagramPaneBase CheckAddPanel(StrategyDataItemInfo info)
        {
            XYDiagram diagram = (XYDiagram)Chart.Diagram;

            if (diagram == null)
            {
                return(null);
            }
            diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;
            if (info.PanelName == "Default")
            {
                return(diagram.DefaultPane);
            }
            XYDiagramPane pane = null;

            if (diagram.Panes[info.PanelName] != null)
            {
                pane = diagram.Panes[info.PanelName];
            }
            IResizeableArray items = GetDataSource(info) as IResizeableArray;

            if (items != null && !(GetArgumentValue(info, items.GetItem(0)) is DateTime))
            {
                if (info.PanelName == "Default")
                {
                }
                else
                {
                    SecondaryAxisX axisX = new SecondaryAxisX();
                    axisX.Name = info.AxisXName;
                    diagram.SecondaryAxesX.Add(axisX);
                }
            }

            if (pane == null || info.Reversed)
            {
                SecondaryAxisY axis = new SecondaryAxisY();
                axis.Assign(diagram.AxisY);
                axis.Name    = info.AxisYName;
                axis.Reverse = info.Reversed;
                diagram.SecondaryAxesY.Add(axis);
            }
            if (pane == null)
            {
                pane = new XYDiagramPane()
                {
                    Name = info.PanelName
                };
                diagram.Panes.Add(pane);
                Legend l = new Legend();
                l.Assign(Chart.Legend); l.Name = info.PanelName;
                l.DockTarget = pane;
                Chart.Legends.Add(l);
            }
            if (!info.PanelVisible)
            {
                pane.Visibility = ChartElementVisibility.Hidden;
            }
            return(pane);
        }
Exemple #3
0
        void Histogram_Load(object sender, EventArgs e)
        {
            m_chart           = new ChartControl();
            m_chart.BackColor = Color.Black;
            m_chart.Dock      = DockStyle.Fill;


            m_chart.CrosshairOptions.ShowCrosshairLabels = false;
            m_chart.CrosshairEnabled = DefaultBoolean.True;
            m_chart.CrosshairOptions.ShowArgumentLabels = true;
            m_chart.CrosshairOptions.ShowValueLabels    = true;

            m_chart.CrosshairOptions.ShowValueLine               = true;
            m_chart.CrosshairOptions.ShowArgumentLine            = true;
            m_chart.CrosshairOptions.CrosshairLabelMode          = CrosshairLabelMode.ShowForNearestSeries;
            m_chart.CrosshairOptions.ArgumentLineColor           = Color.White;
            m_chart.CrosshairOptions.ArgumentLineStyle.DashStyle = DashStyle.Dash;
            m_chart.CrosshairOptions.ValueLineColor              = Color.White;
            m_chart.CrosshairOptions.ValueLineStyle.DashStyle    = DashStyle.Dash;

            // add a fake series
            {
                Series fakeSeries = new Series();
                fakeSeries.LabelsVisibility = DefaultBoolean.False;
                fakeSeries.ShowInLegend     = false;
                m_chart.Series.Add(fakeSeries);
            }
            m_chart.BackColor = Color.Black;

            //// customize chart axes
            CustomizeAxis(DoseCGYAxis, "Dose(cGy)");
            CustomizeAxis(VolumeAxis, "Volume(%)");

            //// Create  secondary axes, and add them to the chart's Diagram.
            DosePercentageAxis = new SecondaryAxisX("Dose(%)");

            CustomizeAxis(DosePercentageAxis, "Dose(%)");

            Diagram.DefaultPane.BorderColor = Color.White;
            Diagram.DefaultPane.BackColor   = Color.Black;

            DoseCGYAxis.CrosshairAxisLabelOptions.Pattern        = "{A:F1}";
            VolumeAxis.CrosshairAxisLabelOptions.Pattern         = "{V:F1}";
            DosePercentageAxis.CrosshairAxisLabelOptions.Pattern = "{A:F1}";

            DoseCGYAxis.CrosshairAxisLabelOptions.TextColor        = Color.Black;
            VolumeAxis.CrosshairAxisLabelOptions.TextColor         = Color.Black;
            DosePercentageAxis.CrosshairAxisLabelOptions.TextColor = Color.Black;

            DoseCGYAxis.CrosshairAxisLabelOptions.BackColor        = Color.White;
            VolumeAxis.CrosshairAxisLabelOptions.BackColor         = Color.White;
            DosePercentageAxis.CrosshairAxisLabelOptions.BackColor = Color.White;

            // Enable the X-axis zooming at the diagram's level.
            Diagram.EnableAxisXZooming = true;
            Diagram.EnableAxisYZooming = true;

            this.panel1.Controls.Add(m_chart);
        }
        // 这个不太对
        public static void AddSecondaryAxisX(this ChartControl chart, Series series)
        {
            SecondaryAxisX myAxisX = new SecondaryAxisX("my X-Axis");

            ((XYDiagram)chart.Diagram).SecondaryAxesX.Add(myAxisX);

            // Assign the series2 to the created axes.
            ((LineSeriesView)series.View).AxisX = myAxisX;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // Create a new chart.
            ChartControl chartControl1 = new ChartControl();

            // Create two series.
            Series series1 = new Series("Series 1", ViewType.Bar);
            Series series2 = new Series("Series 2", ViewType.Line);

            // Add points to them, with their arguments different.
            series1.Points.Add(new SeriesPoint("A", 10));
            series1.Points.Add(new SeriesPoint("B", 12));
            series1.Points.Add(new SeriesPoint("C", 17));
            series1.Points.Add(new SeriesPoint("D", 14));
            series2.Points.Add(new SeriesPoint("I", 1500));
            series2.Points.Add(new SeriesPoint("II", 1800));
            series2.Points.Add(new SeriesPoint("III", 2500));
            series2.Points.Add(new SeriesPoint("IV", 3300));

            // Add both series to the chart.
            chartControl1.Series.AddRange(new Series[] { series1, series2 });

            // Hide the legend (optional).
            chartControl1.Legend.Visible = false;

            // Create two secondary axes, and add them to the chart's Diagram.
            SecondaryAxisX myAxisX = new SecondaryAxisX("my X-Axis");
            SecondaryAxisY myAxisY = new SecondaryAxisY("my Y-Axis");

            ((XYDiagram)chartControl1.Diagram).SecondaryAxesX.Add(myAxisX);
            ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxisY);

            // Assign the series2 to the created axes.
            ((LineSeriesView)series2.View).AxisX = myAxisX;
            ((LineSeriesView)series2.View).AxisY = myAxisY;

            // Customize the appearance of the secondary axes (optional).
            myAxisX.Title.Text      = "A Secondary X-Axis";
            myAxisX.Title.Visible   = true;
            myAxisX.Title.TextColor = Color.Red;
            myAxisX.Label.TextColor = Color.Red;
            myAxisX.Color           = Color.Red;

            myAxisY.Title.Text      = "A Secondary Y-Axis";
            myAxisY.Title.Visible   = true;
            myAxisY.Title.TextColor = Color.Blue;
            myAxisY.Label.TextColor = Color.Blue;
            myAxisY.Color           = Color.Blue;

            // Add the chart to the form.
            chartControl1.Dock = DockStyle.Fill;
            this.Controls.Add(chartControl1);
        }
        internal static AxisBase GetSecondaryAxis(Diagram diagram, ChartAxisType axisType, string name)
        {
            switch (diagram)
            {
            case XYDiagram xyDiagram:
                switch (axisType)
                {
                case ChartAxisType.X:
                    var resultX = new SecondaryAxisX(name);
                    xyDiagram.SecondaryAxesX.Add(resultX);
                    return(resultX);

                case ChartAxisType.Y:
                    var resultY = new SecondaryAxisY(name);
                    xyDiagram.SecondaryAxesY.Add(resultY);
                    return(resultY);
                }
                break;

            case SwiftPlotDiagram swiftPlotDiagram:
                switch (axisType)
                {
                case ChartAxisType.X:
                    var resultX = new SwiftPlotDiagramSecondaryAxisX(name);
                    swiftPlotDiagram.SecondaryAxesX.Add(resultX);
                    return(resultX);

                case ChartAxisType.Y:
                    var resultY = new SwiftPlotDiagramSecondaryAxisY(name);
                    swiftPlotDiagram.SecondaryAxesY.Add(resultY);
                    return(resultY);
                }
                break;

            case XYDiagram3D _:
                throw new Exception("3D charts do not support secondary axes.");

            case RadarDiagram _:
                throw new Exception("Radar chart does not support secondary axes.");

            case SimpleDiagram _:
                throw new Exception("Pie chart does not support axes.");

            case SimpleDiagram3D _:
                throw new Exception("Pie chart does not support axes.");
            }

            throw new Exception("Current chart does not support axes.");
        }
        protected override void AddXAxes(ChartData <BoxWhiskerXValue, BoxWhiskerYValue> chartData, XYDiagram diagram)
        {
            //max value must be greater than min value for axis! For no x axis values we need no x axis.
            if (!chartData.AllXValues.Any())
            {
                return;
            }

            var axisX = diagram.AxisX;

            // because series/curves are not added yet, the AxisX.WholeRange.MaxValue must be modified explicitely
            axisX.WholeRange.MinValue         = -0.5;
            axisX.WholeRange.MaxValue         = chartData.AllXValues.Count() - 1 + 0.5;
            axisX.WholeRange.SideMarginsValue = 0;
            axisX.WholeRange.AutoSideMargins  = false;
            axisX.Visibility = DefaultBoolean.False;

            int nXAxes = chartData.XFieldNames.Count;
            var xAxes  = new SecondaryAxisX[nXAxes];

            for (int i = 0; i < nXAxes; i++)
            {
                xAxes[i] = new SecondaryAxisX(chartData.XFieldNames[i])
                {
                    Visibility = DefaultBoolean.True,
                    Alignment  = AxisAlignment.Far,
                    Tickmarks  = { MinorVisible = false },
                    Title      =
                    {
                        Text       = chartData.XFieldNames[i],
                        Alignment  = StringAlignment.Near,
                        Visibility = DefaultBoolean.False
                    },
                };

                synchronizeAxis(xAxes[i], axisX);
            }

            setXAxesLabels(xAxes, chartData.AllXValues.ToList());

            diagram.SecondaryAxesX.Clear();

            //first XValues most bottom
            for (int i = nXAxes - 1; i >= 0; i--)
            {
                diagram.SecondaryAxesX.Add(xAxes[i]);
            }
        }