我怎么能在Y轴上得到一个0,不管它的值是多少
本文关键字:不管 一个 多少 怎么能 | 更新日期: 2023-09-27 18:06:15
GetMaximum = Gain.Max(); <-- List of Value Numbers Random takes out the maximum
GetMinumumVal = Gain.Min(); <-- takes out the minimum
XAxisScale = GainCounter;
if (XAxisScale % 10 != 0)
{
XAxisScale = (XAxisScale - XAxisScale % 10) + 10; <-- round off to nearest highest 10th
}
intervalXaxis = XAxisScale / 5; <-- divide interval by 5
//------------- Y Axis ---- which needs a 0 neutral ----- //
if(GetMinumumVal > -40)
{
GetMinumumVal = -40;
ConvertToPos = -40; <-- default lowest -40
}
else
{
if (GetMinumumVal % 10 != 0)
{
GetMinumumVal = (GetMinumumVal - GetMinumumVal % 10) - 10;
}
ConvertToPos = Convert.ToInt32(GetMinumumVal) * -1;
}
//-------------//
if(GetMaximum > 60)
{
GetMaximum = Gain.Max();
if (GetMaximum % 10 != 0)
{
GetMaximum = (GetMaximum - GetMaximum % 10) + 10;
}
}
else
{
GetMaximum = 60; <-- Default highest 60
}
Getinterval = (Convert.ToInt32(GetMaximum) + ConvertToPos) / 10; <-- divide by 10 but i need to have zero neutral on it?? this is the problem
Trade_Analyzer_Panel.chart1a.ChartAreas.Add("Area1a");
Trade_Analyzer_Panel.chart1a.Titles.Add("Gain / Loss for Product XYZ");//
Trade_Analyzer_Panel.chart1a.Series.Add("Gain/Loss");
Trade_Analyzer_Panel.chart1a.Legends.Add("Gain/Loss");
Trade_Analyzer_Panel.chart1a.Series["Gain/Loss"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
Count = 0;
for (int i = 0; i < Trade_Analyzer_Panel.dataGridView1.Rows.Count - 1; i++)
{
Trade_Analyzer_Panel.chart1a.Series["Gain/Loss"].Color = Color.Blue;
//Trade_Analyzer_Panel.chart1a.Series["Gain/Loss"].Points[Count].AxisLabel = Convert.ToInt32(Gain[Count]).ToString();
Trade_Analyzer_Panel.chart1a.Series["Gain/Loss"].Points.AddXY(Count, Convert.ToInt32(Gain[Count]));
Count++;
}
// -------- Horizontal ---------- //
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.Minimum = 1;
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.Maximum = XAxisScale;
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.Interval = 5; //intervalXaxis;
// -------- Vertical ---------- //
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisY.Minimum = Convert.ToInt32(GetMinumumVal);
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisY.Maximum = Convert.ToInt32(GetMaximum);
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisY.Interval = 20;
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.ScrollBar.ButtonStyle = System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonStyles.SmallScroll;
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.MajorGrid.Enabled = false;
// set view range to [0,max]
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.Minimum = 0;
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.Maximum = XAxisScale;
// enable autoscroll
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].CursorX.AutoScroll = true;
// let's zoom to [0,blockSize] (e.g. [0,5])
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.ScaleView.Zoomable = true;
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.ScaleView.SizeType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.ScaleView.Zoom(0, 5);
// disable zoom-reset button (only scrollbar's arrows are available)
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.ScrollBar.ButtonStyle = System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonStyles.SmallScroll;
// set scrollbar small change to blockSize (e.g. 100)
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisX.ScaleView.SmallScrollSize = 100;
我应该在这上面使用间隔吗?或者我怎么才能让图表中Y轴的最高和最低值为0。我需要帮助,因为我已经没有主意了,对不起
的例子:
6040 200
-20年-40年但是如果example lower得到-70,它看起来像这样:
50 3010 -10年-30年-50年-70年无论如何改变,我怎么才能得到一个中性的0 ?
注意垂直间距为20
Trade_Analyzer_Panel.chart1a.ChartAreas["Area1a"].AxisY.Interval = 20;
这意味着您在轴上的步数将是最低值加上20的倍数。如果您的底部值是20的倍数,那么您将在其中一个步骤中得到0。可以使用
if(GetMinumumVal > -40)
{
GetMinumumVal = -40;
ConvertToPos = -40; <-- default lowest -40
}
else
{
if (GetMinumumVal % 20 != 0)
{
GetMinumumVal = (GetMinumumVal - GetMinumumVal % 20) - 20;
}
ConvertToPos = Convert.ToInt32(GetMinumumVal) * -1;
}
使用20而不是10。
请注意,模数运算符%对于负数的行为很奇怪,参见http://en.wikipedia.org/wiki/Modulo_operation。如果x是负数,那么x % 20是一个负数。您可能会发现使用Math.Floor(GetMinumumVal / 20)*20
更容易,它是比GetMinumumVal小20的最小倍数。