c# chart缩放,局部放大问题
作者:幻世顽灵 发布时间:2021-09-26 20:46:40
标签:c#,chart缩放,局部放大
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);//当前显示范围最大坐标
c# chart表格
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);//调用滚轮事件
}
来源:https://blog.csdn.net/www89574622/article/details/115910836


猜你喜欢
- 1、用ASCII码判断在 ASCII码表中,英文的范围是0-127,而汉字则是大于127,具体代码如下:string text = &quo
- 本文为大家分享了一个满足在线网页交流需求的实例,由于java Socket实现的网页版在线聊天功能,供大家参考,具体内容如下实现步骤:1、使
- 环境配置Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclis
- springboot通过URL方式访问外部资源遇到这个问题时翻阅百度,无外乎就是两种方式第一种在springboot 2.1.8中该方法已过
- 本文实例为大家分享了OpenGL绘制Bezier曲线的具体代码,供大家参考,具体内容如下项目要求:– 使用鼠标在屏幕中任意设置控制点,并生成
- 1、判断实体对象是否为空2、判断对象所有属性是否为空3、特别注意,实体类中如果有基本数据类型,会影响判断package com.liuxd.
- 最近在做一个多语言切换的功能,类似于微信的语言切换,搜了下资料基本上都是以下这种:1. 实现的效果 和微信类似,在设置界面打开切换
- 前言在日常开发过程中,静态变量和 静态方法 是我们常见的用法,Java中相信大家并不陌生了,那么在 Kotlin 中该如何使用呢
- Redis模糊匹配批量删除操作,使用RedisTemplate操作: public void deleteByPrex(String pre
- 创建SpringBoot项目,启动后,默认的访问路径即主机IP+默认端口号8080:http://localhost:8080/此时,我们就
- 一.安装在 IDEA(2019)的 setting 的 Plugins 的 Marketplace 中搜索 leetcode,即可以找到该插
- 如果我们的程序是在单线程下运行,或者是不必考虑到线程同步问题,我们应该优先使用StringBuilder类;如果要保证线程安全,自然是Str
- 本文实例讲述了Android实现ListView控件的多选和全选功能。分享给大家供大家参考,具体如下:主程序代码MainActivity.J
- springboot 排除redis的自动配置因为要配置一个redis链接,所以将系统自带的配置排除,分别是RedisAutoConfigu
- 作为Android基础组件之一,大家对viewpager已经很熟悉了,网上也有很多使用viewpager来加载图片的案例。但是像微信那样点击
- 一、Android Studio 主题的设置1.1 设置Android Studio 自带的主题及包名字体大小1.2 导入第三方主题:下载了
- 基本操作示例VectorApp.javaimport java.util.Vector; import java.lang.*; impor
- Android 6.0起,Android加强了权限管理,引入运行时权限概念。对于:1. Android 5.1(API 22)及以前版本,应
- 一、概述数据透视表(Pivot Table)是一种交互式的表,可以进行某些计算,如求和与计数等,可动态地改变透视表版面布置,也可以重新安排行
- 当遇到以下场景:其他人写的单元测试影响统计结果一些需要调用外部接口的测试暂不运行需要在非本机环境上运行一些不回滚的单元测试则有必要选择以下方