2012-12-21 15 views
5

में एक्स-अक्ष में केवल कस्टम लेबल का उपयोग करें, मैं सप्ताहों के एक्स-अक्ष अंतराल के साथ सी # में .NET रेखा ग्राफ बना रहा हूं। मेरी परियोजना के लिए, मैं केवल कस्टम लेबल का उपयोग करना चाहता हूं, लेकिन अभी भी मैं अभी भी ग्रिडलाइन चाहता हूं। क्या कस्टम कस्टम लेबल रखते हुए डिफ़ॉल्ट एक्स-एक्सिस लेबल को छिपाने का कोई तरीका जानता है?.NET चार्ट

मैं इस कोशिश की:

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

स्पष्ट परिणाम लागू किया है, जो नहीं है कि मैं क्या करने की कोशिश कर रहा था कोई लेबल नहीं थे कि है।

संपादित करें: मूल पंक्तियों पैदा करने के लिए कोड इस था:

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); 

चार्ट इस तरह दिखता है: Chart with dates

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

और कस्टम लेबल के लिए कोड इस था

और यह इस तरह दिखना चाहिए: chart without dates

+0

आप कॉलम चार्ट देखना चाहते हैं – Jerome

उत्तर

5

ठीक है, मैंने MSDN पर Label नियंत्रणों को देखा। सामान्य लेबल के स्थान पर कस्टम लेबल दिखाई देने के लिए, मैंने RowIndex पैरामीटर को 0 पर सेट किया है, डिफ़ॉल्ट लेबल पंक्ति को बदल दिया है। कस्टम पंक्तियों के लिए अंतिम कोड इस तरह दिखता था:

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); 
संबंधित मुद्दे