我的图表如下所示:
我可以通过更改图表下方文本框中的值(X-min和X-max)来操纵x轴的比例。最小值和最大值始终四舍五入为可以除以10且无余数的数字。 (858得到860,-107得到-110)。现在,我正在寻找一种解决方案,以获取X轴刻度,该轴始终在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
(如果将其设置为“自动AxisX.Minimum
返回NaN”)。编辑:还要求您将
chart.ChartAreas[0].AxisX.Interval
设置为Auto以外的其他值