2016-06-10 180 views
1

我对图表区域和特定比例的特定地点查看数据正确,我不想使用自动量程更改X轴的刻度相同的数据序列图

我要的是,..如果点>“ chart.ChartAreas [0] .AxisX.Maximum' 用新的X轴缩放重新绘制点。与改变线的颜色,所以我可以找出它的超标度

我的第一个刻度0 --- 90 我在规模90 ---- 180

正如你在这里看到的enter image description here
我想删除这一点与规模与红色系的颜色重新绘制它从90到180,然后完成我的正常

这就是我想要实现enter image description here

着点,这是我的代码我尝试了两种不同的系列,但无法正常工作,我是失去了一些东西,我从CSV文件中读取数据(nLines代表行数)

 for (int j = 0; j < nLines; j++) 
     { 

      chart.Series["Series0"].Points.AddXY(data[j, indX], data[j, indY]); 


      chart.ChartAreas[0].AxisY.IsReversed = true; 
      chart.ChartAreas[0].AxisX.Minimum = 0; 
      chart.ChartAreas[0].AxisX.Maximum = 90; 
      chart.Series["Series0"].Color = Color.Blue; 
      chart.Series["Series0"].BorderWidth = 2; 




      List<DataPoint> lst = chart.Series["Series0"].Points.ToList<DataPoint>(); 





       if (lst[j].XValue > 90) 
       { 


        chart.Series["Series15"].ChartType = SeriesChartType.StepLine; 
        chart.Series["Series15"].Points.AddXY(data[j, indX], data[j, indY]); 


        chart.Series["Series15"].XAxisType = AxisType.Secondary; 
        chart.ChartAreas[0].AxisX2.Minimum = 90; 
        chart.ChartAreas[0].AxisX2.Maximum = 180; 
        chart.ChartAreas[0].AxisX2.MajorGrid.Enabled = false; 
        chart.ChartAreas[0].AxisX2.MinorGrid.Enabled = false; 
        chart.Series["Series15"].Color = Color.Red; 
        chart.Series["Series15"].BorderWidth = 2; 

       } 
     } 

回答

2

还有就是要做到这一点不止一种方法,但最简单的使用技巧:

由于任何一个Chartarea只能显示一个我们使用的值的范围和范围两个Chartareas覆盖他们。

一个有正常范围,另一个溢出范围。

现在,我们的所有数据添加到两个系列:onece正常chartarea,又在溢出区..

下面是结果:

enter image description here

下面是如何准备在Chart

ChartArea ca1 = chart1.ChartAreas[0]; 

// the regular axis label interval and range 
ca1.AxisX.Interval = 10; 
ca1.AxisX.Minimum = 0; 
ca1.AxisX.Maximum = 100; 

// we add an extra chartarea 
ChartArea ca2 = chart1.ChartAreas.Add("ca2"); 
// we align it.. 
ca2.AlignmentOrientation = AreaAlignmentOrientations.All; 
ca2.AlignWithChartArea = ca1.Name; 
// ..but we also need to set the position 
// we create a hard coded element position that leaves room for labels and legend 
ca1.Position = new ElementPosition(0, 0, 80, 90); // 80% width 
ca2.Position = new ElementPosition(0, 0, 80, 90); // 90% height 
// we make the overlayed area transparent 
ca2.BackColor = Color.Transparent; 
// it needs a series to display the overflowing points 
Series S22 = chart1.Series.Add("OverFlow"); 
S22.ChartType = SeriesChartType.StepLine; 
S22.Color = Color.Red; 
S22.ChartArea = "ca2"; 

其余部分基本上只是造型的轴。

// we want to show a secondary axis on top: 
ca2.AxisX2.Enabled = AxisEnabled.True; 
// don't disable the primary axis if you want any labels! 
// instead make its labels transparent! 
ca2.AxisX.LabelStyle.ForeColor = Color.Transparent; 
// this is shared by the sec.axis event though it has its own property! 
ca2.AxisX.LabelStyle.Interval = 10; 
// I color the axis and the labels 
ca2.AxisX2.LineColor = S22.Color; 
ca2.AxisX2.LabelStyle.ForeColor = S22.Color; 
// we need to set the range for both (!) axes: 
ca2.AxisX2.Minimum = 100; 
ca2.AxisX2.Maximum = 200; 
ca2.AxisX.Minimum = 100; 
ca2.AxisX.Maximum = 200; 

现在您可以将您的值添加到两个未修改的系列中。

我使用范围0-100和100-200。当然你的工作也会如此。另外:如果您不需要Legend,您可以将宽度从80%扩大到90%或更多。

这比在同一个chartarea中仅将溢出点添加到另一个系列要容易很多,因为看起来不错,还需要通过在正确的位置添加透明的额外点来防止间隙和虚假连接。

+0

感谢您的帮助,..为我w,,..我想要点超标,如果我想从蓝线删除,我只是检查并删除它们,但这将需要填补空白,每当我对吗? – user1477332

+0

我不知道为什么你想删除一个点。在我的解决方案中,您将所有的点添加到两个系列。 。一般情况:从线型(线,样条线,快速线,步进线)移除点不会产生间隙,但根据目的,它将创建错误的连接,因为该点的邻居已连接。 。所以这通常不是人们想要的。相反,您可以尝试将要消失的点(也可能是下一个点)的颜色更改为“Color.Transparent”。 – TaW

+0

非常感谢您的帮助,是的,您是对的,我已经尝试删除积分并将其错误连接:D,...我认为Color.Transparent会做得更好,...再次感谢您的帮助 – user1477332