溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

c#?chart縮放和局部放大問(wèn)題怎么解決

發(fā)布時(shí)間:2023-03-01 11:25:52 來(lái)源:億速云 閱讀:279 作者:iii 欄目:開(kāi)發(fā)技術(shù)

今天小編給大家分享一下c# chart縮放和局部放大問(wèn)題怎么解決的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來(lái)了解一下吧。

    c# chart縮放,局部放大

    效果:

    左鍵劃選放大區(qū)域,右鍵恢復(fù)

            /// <summary>
            /// 初始化,傳入要進(jìn)行初始化的chart
            /// </summary>
            /// <param name="chart1"></param>
            public static void InitChart (System.Windows.Forms.DataVisualization.Charting.Chart chart1)
            {
                //開(kāi)啟縮放功能
                chart1.ChartAreas[0].CursorX.Interval = 0;
                chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
                chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
                chart1.MouseClick += new System.Windows.Forms.MouseEventHandler(chart_MouseClick);
            }
     
            //右鍵恢復(fù)縮放
            static void chart_MouseClick(object sender, MouseEventArgs e)
            {
                Chart chart1 = sender as Chart;
                //右鍵恢復(fù)事件
                if (e.Button == MouseButtons.Right)
                {
                    chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset(0);
                }
            }

    放大

    僅針對(duì)x軸(y軸同理)

    chartArea1.CursorX.IsUserEnabled = true;
    chartArea1.CursorX.IsUserSelectionEnabled = true;

    縮小

    chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
    • ZoomReset(0); &mdash;&mdash; 撤銷所有放大動(dòng)作

    • ZoomReset(1); &mdash;&mdash; 撤銷上一次放大動(dòng)作

    設(shè)置滾動(dòng)條寬度

    chart1.ChartAreas[0].AxisX.ScrollBar.Size = 5;

    以上所有方法也可以在chart屬性里直接進(jìn)行設(shè)置

    獲取選區(qū)坐標(biāo)

    Console.WriteLine(chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum);//當(dāng)前顯示范圍最小坐標(biāo)
    Console.WriteLine(chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum);//當(dāng)前顯示范圍最大坐標(biāo)

    c# chart表格

    • series1屬性中XAxisType屬性值設(shè)置為:Primary

    • series2屬性中XAxisType屬性值設(shè)置為:Secondary          

    添加series會(huì)導(dǎo)致圖表預(yù)覽不可用

    c#?chart縮放和局部放大問(wèn)題怎么解決

    設(shè)置間隔與小數(shù)點(diǎn)

    c#?chart縮放和局部放大問(wèn)題怎么解決

    網(wǎng)格刻度

     #region 表格參數(shù)設(shè)置
                //ChartArea chartArea = chart1.ChartAreas[0];
     
                //表格標(biāo)題內(nèi)容
                Title title = new Title();
                title.Font = new System.Drawing.Font("宋體", 12F);
                title.Text = "壓機(jī)曲線波動(dòng)分析";
                chart1.Titles.Add(title);
     
                //設(shè)置坐標(biāo)軸標(biāo)題
                chart1.ChartAreas[0].AxisX.Title = "位 移 / mm ";
                chart1.ChartAreas[0].AxisY.Title = "壓  力 / Kg ";
     
                //X,Y軸的最大值最小值
                chart1.ChartAreas[0].AxisX.Minimum = 0;
                chart1.ChartAreas[0].AxisX.Maximum = 100;
                chart1.ChartAreas[0].AxisY.Minimum = 0;
                chart1.ChartAreas[0].AxisY.Maximum = 200;
     
                // 設(shè)置X,Y的坐標(biāo)間距
                chart1.ChartAreas[0].AxisX.Interval = 1;
                chart1.ChartAreas[0].AxisY.Interval = 5;
     
     
                //設(shè)置坐標(biāo)軸標(biāo)題的字體
                chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("宋體", 12F);
                chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("宋體", 12F);
     
                //設(shè)置坐標(biāo)軸柵格是否可見(jiàn)
                chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
                chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
     
                //設(shè)置網(wǎng)格線  
                chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Gainsboro;   //顏色
                chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 10;                 //網(wǎng)格間隔
                chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 10;
                chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Gainsboro;
                chart1.ChartAreas[0].AxisY.MajorGrid.Interval = 20;
                chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 20;
     
                放大表格
                chart1.ChartAreas[0].AxisX.ScaleView.Zoom(2, 3);
                chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = false;
                chart1.ChartAreas[0].AxisX.ScaleView.Size = 20;
     
                 Zoom into the X axis
                 Enable range selection and zooming end user interface
                chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
                chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
                chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
     
                //將滾動(dòng)內(nèi)嵌到坐標(biāo)軸中
                chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
                chart1.ChartAreas[0].AxisY.ScrollBar.IsPositionedInside = true;
     
     
     
                #endregion
     
     
                #region 各個(gè)曲線參數(shù)設(shè)置
                //曲線類型
                chart1.Series[0].ChartType = SeriesChartType.Spline;
                chart1.Series[1].ChartType = SeriesChartType.Spline;
                chart1.Series[10].ChartType = SeriesChartType.Spline;
     
                // 曲線 線寬像素
                chart1.Series[0].BorderWidth = 1;
                chart1.Series[1].BorderWidth = 1;
                chart1.Series[10].BorderWidth = 3;
     
                // 曲線的顏色
                chart1.Series[10].Color = System.Drawing.Color.Red;
                chart1.Series[4].Color = System.Drawing.Color.Green;
                chart1.Series[5].Color = System.Drawing.Color.RoyalBlue;
     
                //右上角的曲線名稱是否顯示
                chart1.Series[0].IsVisibleInLegend = true;
                chart1.Series[1].IsVisibleInLegend = true;
                chart1.Series[10].IsVisibleInLegend = true;
     
                //右上角的曲線名稱
     
     
                chart1.Series[0].LegendText = "隨機(jī)抽取曲線1";
                chart1.Series[1].LegendText = "隨機(jī)抽取曲線2";
                chart1.Series[2].LegendText = "隨機(jī)抽取曲線3";
                chart1.Series[3].LegendText = "隨機(jī)抽取曲線4";
                chart1.Series[4].LegendText = "隨機(jī)抽取曲線5";
                chart1.Series[5].LegendText = "隨機(jī)抽取曲線6";
                chart1.Series[6].LegendText = "隨機(jī)抽取曲線7";
                chart1.Series[7].LegendText = "隨機(jī)抽取曲線8";
                chart1.Series[8].LegendText = "隨機(jī)抽取曲線9";
                chart1.Series[9].LegendText = "隨機(jī)抽取曲線10";
                chart1.Series[10].LegendText = "Average";
     
                //名稱的懸浮備注
                chart1.Series[10].LegendToolTip = "此乃10個(gè)隨機(jī)曲線的平均值曲線";
                chart1.Series[0].LegendToolTip = "隨機(jī)抽取曲線1備注";
                chart1.Series[1].LegendToolTip = "備注2";
     
                //坐標(biāo)Y值是否顯示在圖表中
                //chart1.Series[0].IsValueShownAsLabel = true;
                //chart1.Series[1].IsValueShownAsLabel = true;
                //chart1.Series[2].IsValueShownAsLabel = true;
                //chart1.Series[3].IsValueShownAsLabel = true;
                //chart1.Series[4].IsValueShownAsLabel = true;
                chart1.Series[10].IsValueShownAsLabel = true;
     
                //chart1.Series.Clear();     使表格GGG
                //chart1.Series.Dispose();
                #endregion
      //設(shè)置網(wǎng)格線
                chartDemo1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;
                chartDemo1.ChartAreas[0].AxisX.MajorGrid.Interval = 500;//網(wǎng)格間隔
                chartDemo1.ChartAreas[0].AxisX.MinorGrid.Interval = 500;
                chartDemo1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash; //設(shè)置網(wǎng)格類型為虛線
                chartDemo1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;
                chartDemo1.ChartAreas[0].AxisY.MajorGrid.Interval = 4;
                chartDemo1.ChartAreas[0].AxisY.MinorGrid.Interval = 4;
                chartDemo1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;//網(wǎng)格Y軸線類型
                this.chartDemo1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Transparent;
                //    this.chartDemo1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Transparent;
    //滑輪設(shè)置  
     chartDemo1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss"; 
                chartDemo1.ChartAreas[0].AxisX.ScaleView.Size = 8;
                chartDemo1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
                chartDemo1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
       private void chart1_MouseEnter(object sender, MouseEventArgs e)
            {
                if (e.Delta > 0)//鼠標(biāo)向上
                {
                    if (chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size < 100)//判斷顯示的最大數(shù)值
                    {
                        // chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size += 2;//+=5---滾動(dòng)一次顯示5個(gè)
                        chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position += 2;
                    }
                }
                else//鼠標(biāo)向下滾動(dòng)
                {
                    if (chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size > 1)
                    {
                        // chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size -= 2;// - = 5---滾動(dòng)一次減小顯示5個(gè)
                        chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position -= 2;
                    }
                  
                }
            }
            private void chart1_MouseEnter(object sender, EventArgs e)//當(dāng)鼠標(biāo)移動(dòng)到控件上-發(fā)生的事件
            {
                MouseWheel += new MouseEventHandler(chart1_MouseEnter);//調(diào)用滾輪事件
            }

    以上就是“c# chart縮放和局部放大問(wèn)題怎么解決”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

    向AI問(wèn)一下細(xì)節(jié)

    免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

    AI