2016-06-10 112 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