none
Trendline.DataLabel.Text returns empty string RRS feed

  • Question

  • I am creating a trendline in excel chart using C# VSTO.

    Though I am able to see the datalabels on the trendlines but when i try to access the Datalabel.Tex, I get an empty string.

    I don't know what is the issue?

     

    using IExcel = Microsoft.Office.Interop.Excel; 


    IExcel.Trendlines trendlines = (IExcel.Trendlines)series.Trendlines(System.Type.Missing);
    
    IExcel.Trendline newTrendline = trendlines.Add(IExcel.XlTrendlineType.xlLinear, Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, true, false, System.Type.Missing);
    
    
     IExcel.Range P15 = rngEquation.Cells[1,2] as IExcel.Range;
    //this is where i get value = "" ,i.e., Text is not returned by this //property.
    
     P15.Value2 = newTrendline.DataLabel.Text;
    

     

    Also, sometimes I get the value for first trendline that i have shown above. but other datalables for other trendline never show up dynamically, though they are visible on chart. 

      IExcel.Trendline logTrendline = trendlines.Add(IExcel.XlTrendlineType.xlLogarithmic, Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, true, false, System.Type.Missing);
    
            //exponential trendline
    
            IExcel.Trendline expTrendline = trendlines.Add(IExcel.XlTrendlineType.xlExponential, Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, true, false, System.Type.Missing);
    
            //quadratic trendline
    
            IExcel.Trendline quadTrendline = trendlines.Add(IExcel.XlTrendlineType.xlPolynomial, Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, true, false, System.Type.Missing);
    
    
     string[] str = new string[4];
    
            str[0] = newTrendline .DataLabel.Text;
    
            str[1] = logTrendline .DataLabel.Text;
    
            str[2] = expTrendline .DataLabel.Text;
    
            str[3] = quadTrendline .DataLabel.Text;

     


    Regards Piya :)



    Friday, March 18, 2011 9:12 AM

All replies

  • Hi Piya.Bhat,

    Thanks for posting in the MSDN Forum.

    I don’t not why, but I can get the DataLabel Text. If you want to get it please put a MessageBox above it and show series.Forumal first. I test it on my side, and it works fine.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 22, 2011 8:00 AM
    Moderator