gpt4 book ai didi

c# - 在图表的 X Axis 的点 0 处获取网格线/间隔(灵活的 Axis 缩放)

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:38 25 4
gpt4 key购买 nike

我的图表如下所示:c# chart

我可以通过更改图表下方文本框(X-min 和 X-max)中的值来操纵 x Axis 的比例。最小值和最大值始终四舍五入为可被 10 整除而无余数的数字。 (858 得到 860,-107 得到 -110)。现在我正在寻找一种解决方案来获得 X Axis 刻度,它始终在 X 点“0”处有一条线(图中标记为红色)。

我正在使用 C#。

部分代码如下:

private void textBoxXmax_TextChanged(object sender, EventArgs e)
{
double max, min;

Double.TryParse(this.textBoxXmin.Text, out min);
//checks if the Entering is a double number and if it is greater than the min value
if (Double.TryParse(this.textBoxXmax.Text, out max) && max > chartTest.ChartAreas[0].AxisX.Minimum)
{
max = Math.Round(max / 10) * 10; //round to tens (113->110)
//MessageBox.Show(x.ToString());
this.textBoxXmax.BackColor = Color.White;
chartTest.ChartAreas[0].AxisX.Maximum = max;
//chartCharacteristicCurvesResistanceThermometer.ChartAreas[0].AxisX.Interval = (max-min)/10;
//Problem should be here

//set the YScaleMax
changeYScala(chartTest);
}
else
//if not the textbox is highlighted
this.textBoxXmax.BackColor = Color.Orange;

//double y;
//checks if the Entering is a double number and if it is smaler than the max value
if (Double.TryParse(this.textBoxXmin.Text, out min) && min < chartTest.ChartAreas[0].AxisX.Maximum)
{
min = Math.Round(min / 10) * 10; //round to tens (113->110)
this.textBoxXmin.BackColor = Color.White;
chartTest.ChartAreas[0].AxisX.Minimum = min;
//same calculation for Interval here

changeYScala(chartTest);
}
else
//if not the textbox is highlighted
this.textBoxXmin.BackColor = Color.Orange;
}

最佳答案

您可以使用 chart.ChartAreas[0].AxisX.IntervalOffset 更改间隔的偏移量,另外我通过反复试验发现了这一点,我不知道为什么会这样,但正确的偏移量似乎是:

chart.ChartAreas[0].AxisX.IntervalOffset = 
(-chart.ChartAreas[0].AxisX.Minimum) % chart.ChartAreas[0].AxisX.Interval;

此解决方案要求您手动设置 AxisX.Minimum(如果设置为 Auto AxisX.Minimum 返回 NaN)。

编辑:还需要您将 chart.ChartAreas[0].AxisX.Interval 设置为 Auto 以外的值

关于c# - 在图表的 X Axis 的点 0 处获取网格线/间隔(灵活的 Axis 缩放),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33260502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com