簡體   English   中英

如何在圖表區域內顯示 Y 軸標簽

[英]how to display Y axis labels inside chart area

我有一個時間軸,我想在圖表區域內而不是在外面顯示我的 Y 軸標簽

這是我的代碼

        Series newSeries = new Series("hkld");
        newSeries.ChartType = SeriesChartType.Line;
        newSeries.BorderWidth = 2;
        newSeries.Color = Color.OrangeRed;
        newSeries.XValueType = ChartVal

        chart1.ChartAreas[0].AxisY.IsReversed = true;
        chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
        chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
        chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 2;
        chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;
        chart1.ChartAreas[0].AxisX.Minimum = 0;
        chart1.ChartAreas[0].AxisX.Maximum = 1000000; 
        chart1.ChartAreas[0].AxisX.Interval = 200000; //major interval
        chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 20000; //minor interval
        chart1.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot;
        chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
        chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
        chart1.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Minutes;
        chart1.ChartAreas[0].AxisY.Interval = 2;
        chart1.ChartAreas[0].AxisY.LabelStyle.Format = "HH:mm:ss";
        chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
        chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = true;
        chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 2;
        chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;
        chart1.ChartAreas[0].AxisY.MinorGrid.IntervalType =               DateTimeIntervalType.Minutes;
        chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 2;
        chart1.ChartAreas[0].AxisY.MinorGrid.LineDashStyle = ChartDashStyle.Dash;
        chart1.ChartAreas[0].BorderColor = Color.Black;
        chart1.ChartAreas[0].BorderWidth = 3;
        chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
        chart1.ChartAreas[0].Position.X = 5;
        chart1.ChartAreas[0].Position.Y = 5;
        chart1.ChartAreas[0].Position.Width = 90;
        chart1.ChartAreas[0].Position.Height = 90;
        chart1.ChartAreas[0].InnerPlotPosition.Height = 100;
        chart1.ChartAreas[0].InnerPlotPosition.Width = 80;
        chart1.ChartAreas[0].InnerPlotPosition.X = 20;
        chart1.ChartAreas[0].Position.Auto = false;

這是我的圖表的圖片:

在此處輸入圖片說明

這是我想要實現的目標:

在此處輸入圖片說明

注意:我的圖表是實時圖表,所以時間值會隨着時間的推移而更新和上升(動態軸)

我認為您不能移動標簽,但您可以隨標簽移動軸。 為此,請為AxisX.Crossing設置一個合適的值。

微軟:

為主軸設置此屬性將確定另一個主軸與其相交的位置,類似地為次軸設置此屬性將確定另一個次軸與其相交的位置。 例如,設置主 X 軸的 Crossing 屬性確定主 Y 軸與它相交的位置。

軸的 Crossing 屬性可使用四種模式:

  • “自動”,這意味着交叉值將設置為相關軸的最小值或最大值......

  • “最小值”,這意味着軸的交叉值將是它的最小值......

  • “最大值”,這意味着軸的交叉值將是它的最大值......

  • 位於相關軸的最小值和最大值之間的指定雙精度值...

這將其移動到最后一個數據點的 x 值:

Axixs ax = chart1.ChartAreas[0].AxisX;
ax.Crossing = mySeries.Points.Last().XValue;

如果您知道您的數據,您可以使用固定值。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM