2012-12-21 32 views
5

Tworzę wykres linii .NET w języku C# z interwałem tygodniowym w osi X. W przypadku mojego projektu chcę używać tylko etykiety niestandardowej, ale na razie wciąż chcę linii siatki. Czy ktoś wie, jak ukryć domyślne etykiety X-Axis, zachowując przy tym własne etykiety?Użyj tylko niestandardowej etykiety w osi X na wykresie .NET

Próbowałem to:

Chart4.ChartAreas[0].AxisX.LabelStyle.Enabled = false; 

Oczywistym efektem jest to, że nie było etykiety stosowane, co nie jest, co starałem się zrobić.

EDIT: Kod do generowania oryginalnych wierszy było to:

Chart4.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "M"; 

I kod dla niestandardowego etykiecie było to:

int month = XValues[0].Month; 
var XAxis = Chart4.ChartAreas[0].AxisX; 

DateTime StartMonthPos = XValues[0]; 
DateTime EndPos = new DateTime(); 

foreach (DateTime Date in XValues) 
{ 
    EndPos = Date; 

    if (Date.Month != month) 
    { 
     Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None); 
     StartMonthPos = Date; 
    } 

    month = Date.Month; 
} 

XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None); 

tabela wygląda następująco: Chart with dates

Powinno to wyglądać tak: chart without dates

+0

Może zajrzeć do kolumnowych wykresów – Jerome

Odpowiedz

5

W porządku, sprawdziłem formanty Label na MSDN. Aby ustawić niestandardową etykietę zamiast normalnej etykiety, ustawiłem parametr RowIndex na 0, zastępując domyślny wiersz etykiety. Końcowy kod dla niestandardowych wierszy wyglądał następująco:

int month = XValues[0].Month; 
    var XAxis = Chart4.ChartAreas[0].AxisX; 

    DateTime StartMonthPos = XValues[0]; 
    DateTime EndPos = new DateTime(); 

    foreach (DateTime Date in XValues) 
    { 
     EndPos = Date; 

     if (Date.Month != month) 
     { 
      Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(), 
       EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 0, LabelMarkStyle.None); 
      StartMonthPos = Date; 
     } 

     month = Date.Month; 
    } 

    XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), 
      StartMonthPos.ToString("MMMM"), 0, LabelMarkStyle.None); 
Powiązane problemy