您好,登錄后才能下訂單哦!
今天小編給大家分享一下c# chart縮放和局部放大問題怎么解決的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
效果:
左鍵劃選放大區域,右鍵恢復
/// <summary> /// 初始化,傳入要進行初始化的chart /// </summary> /// <param name="chart1"></param> public static void InitChart (System.Windows.Forms.DataVisualization.Charting.Chart chart1) { //開啟縮放功能 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); } //右鍵恢復縮放 static void chart_MouseClick(object sender, MouseEventArgs e) { Chart chart1 = sender as Chart; //右鍵恢復事件 if (e.Button == MouseButtons.Right) { chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset(0); } }
僅針對x軸(y軸同理)
chartArea1.CursorX.IsUserEnabled = true; chartArea1.CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
ZoomReset(0);
—— 撤銷所有放大動作
ZoomReset(1);
—— 撤銷上一次放大動作
設置滾動條寬度
chart1.ChartAreas[0].AxisX.ScrollBar.Size = 5;
以上所有方法也可以在chart屬性里直接進行設置
獲取選區坐標
Console.WriteLine(chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum);//當前顯示范圍最小坐標 Console.WriteLine(chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum);//當前顯示范圍最大坐標
series1屬性中XAxisType屬性值設置為:Primary
series2屬性中XAxisType屬性值設置為:Secondary
添加series會導致圖表預覽不可用
#region 表格參數設置 //ChartArea chartArea = chart1.ChartAreas[0]; //表格標題內容 Title title = new Title(); title.Font = new System.Drawing.Font("宋體", 12F); title.Text = "壓機曲線波動分析"; chart1.Titles.Add(title); //設置坐標軸標題 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; // 設置X,Y的坐標間距 chart1.ChartAreas[0].AxisX.Interval = 1; chart1.ChartAreas[0].AxisY.Interval = 5; //設置坐標軸標題的字體 chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("宋體", 12F); chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("宋體", 12F); //設置坐標軸柵格是否可見 chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true; chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true; //設置網格線 chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Gainsboro; //顏色 chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 10; //網格間隔 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; //將滾動內嵌到坐標軸中 chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true; chart1.ChartAreas[0].AxisY.ScrollBar.IsPositionedInside = true; #endregion #region 各個曲線參數設置 //曲線類型 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 = "隨機抽取曲線1"; chart1.Series[1].LegendText = "隨機抽取曲線2"; chart1.Series[2].LegendText = "隨機抽取曲線3"; chart1.Series[3].LegendText = "隨機抽取曲線4"; chart1.Series[4].LegendText = "隨機抽取曲線5"; chart1.Series[5].LegendText = "隨機抽取曲線6"; chart1.Series[6].LegendText = "隨機抽取曲線7"; chart1.Series[7].LegendText = "隨機抽取曲線8"; chart1.Series[8].LegendText = "隨機抽取曲線9"; chart1.Series[9].LegendText = "隨機抽取曲線10"; chart1.Series[10].LegendText = "Average"; //名稱的懸浮備注 chart1.Series[10].LegendToolTip = "此乃10個隨機曲線的平均值曲線"; chart1.Series[0].LegendToolTip = "隨機抽取曲線1備注"; chart1.Series[1].LegendToolTip = "備注2"; //坐標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
//設置網格線 chartDemo1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray; chartDemo1.ChartAreas[0].AxisX.MajorGrid.Interval = 500;//網格間隔 chartDemo1.ChartAreas[0].AxisX.MinorGrid.Interval = 500; chartDemo1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash; //設置網格類型為虛線 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;//網格Y軸線類型 this.chartDemo1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Transparent; // this.chartDemo1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Transparent;
//滑輪設置 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)//鼠標向上 { if (chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size < 100)//判斷顯示的最大數值 { // chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size += 2;//+=5---滾動一次顯示5個 chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position += 2; } } else//鼠標向下滾動 { if (chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size > 1) { // chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size -= 2;// - = 5---滾動一次減小顯示5個 chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Position -= 2; } } } private void chart1_MouseEnter(object sender, EventArgs e)//當鼠標移動到控件上-發生的事件 { MouseWheel += new MouseEventHandler(chart1_MouseEnter);//調用滾輪事件 }
以上就是“c# chart縮放和局部放大問題怎么解決”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。