c# – 根据几个系列的X值的一部分中的值,缩放图表的Y轴
发布时间:2020-12-15 18:29:40 所属栏目:百科 来源:网络整理
导读:我有一个这样的应用: 使用图表下方的文本框,用户可以设置图表的X轴的最小值和最大值.这是它的代码: private void textBoxXaxisMin_TextChanged(object sender,EventArgs e){ double x; //checks if the input is a double and smaller than the max value
我有一个这样的应用:
使用图表下方的文本框,用户可以设置图表的X轴的最小值和最大值.这是它的代码: private void textBoxXaxisMin_TextChanged(object sender,EventArgs e) { double x; //checks if the input is a double and smaller than the max value //if (Double.TryParse(this.textBoxXaxisMin.Text,out x) && x < chart1.ChartAreas[0].AxisX.Maximum) if (Double.TryParse(this.textBoxXaxisMin.Text,out x)) { this.textBoxXaxisMin.BackColor = Color.White; chart1.ChartAreas[0].AxisX.Minimum = Convert.ToDouble(this.textBoxXaxisMin.Text); //changeYScalaMin(chartCharacteristicCurvesThermoelemts,Convert.ToDouble(this.textBoxCharacteristicCurvesThermoelementXmin.Text),Convert.ToDouble(this.textBoxCharacteristicCurvesThermoelementXmax.Text)); //method to scale y axis } else //if the textbox is not highlighted this.textBoxXaxisMin.BackColor = Color.Orange; //calls the Max Function to update the chart if the Max-value is now valid double y; //checks if the input is a double and greater than the min value if (Double.TryParse(this.textBoxXaxisMax.Text,out y) && y > chart1.ChartAreas[0].AxisX.Minimum) { this.textBoxXaxisMax.BackColor = Color.White; chart1.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(this.textBoxXaxisMax.Text); //method to scale y axis } else //if the textbox is not highlighted this.textBoxXaxisMax.BackColor = Color.Orange; } 现在我想让Y轴自动缩放.应将Y-min计算为(X-min和X-max)部分中所有系列的最小值,并将Y-max计算为所选部分中所有系列的最大值.我的问题是实施. 在此示例中,Y-min应更改为大约50. 我在GitHup处主持了这个漏洞示例项目. 解决方法
对于从0到1的所有系列,这会将Y轴缩放到X轴的最小值和最大值[0]之间的最小值和最大值:
double max = Double.MinValue; double min = Double.MaxValue; double leftLimit = chart1.ChartAreas[0].AxisX.Minimum; double rightLimit = chart1.ChartAreas[0].AxisX.Maximum; for (int s = 0; s <= 1; s++) { foreach (DataPoint dp in chart1.Series[s].Points) { if (dp.XValue >= leftLimit && dp.XValue <= rightLimit) { min = Math.Min(min,dp.YValues[0]); max = Math.Max(max,dp.YValues[0]); } } } chart1.ChartAreas[0].AxisY.Maximum = max; chart1.ChartAreas[0].AxisY.Minimum = min; 编辑:测试时我注意到重置最小值和最大值并不是很明显.方法如下: chart1.ChartAreas[0].AxisY.Minimum = Double.NaN; chart1.ChartAreas[0].AxisY.Maximum = Double.NaN; chart1.ChartAreas[0].AxisX.Minimum = Double.NaN; chart1.ChartAreas[0].AxisX.Maximum = Double.NaN; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Haskell FFI – 如何处理接受或返回结构体而不是结构体指针
- Cocos2d-x-Lua出乎意料的性能短板——那个getPosition的bin
- ruby – 有一个干净的方法来访问哈希数组中的哈希值吗?
- 加密 – 在React Native和Expo中加密敏感数据
- 使用SQLAlchemy,SQLite和Postgresql的模式限定表?
- 原型JSF更新验证失败后不起作用
- c# – 如何在CookieContainer中获取Cookie信息? (所有他们
- cocos2dx在暂停某些元素后导致crash问题
- xml,configpraser,hashlib模块
- 正则表达式 – Mac OSX,Bash,awk和负面看后面