.NET Framework Developer Center > .NET Development Forums > Chart Controls for .NET Framework > How to format label when doing .Points.DataBind

Answer How to format label when doing .Points.DataBind

  • Thursday, April 30, 2009 12:54 AM
     
     
    I'm binding my data:

    Chart1.Series("Series1").Points.DataBind(myDataView, "Date", "Inv", "Tooltip=Variety, Label=Inv")
    The chart displays properly, but I am unable to format the Label. 

    I've tried the following but cannot get it to work:

    Chart1.Series("Series1").LabelFormat = "#,##0;(#,##0); "
    as well as
    For

    i As Integer = 0 To Chart1.Series("Series1").Points.Count - 1
    Chart1.Series(
    "Series1").Points(i).LabelFormat = "#,##0;(#,##0); "
    Next i

     

    i As Integer = 0 To Chart1.Series("Series1").Points.Count - 1
    Chart1.Series(
    "Series1").Points(i).LabelFormat = "#,##0;(#,##0); "
    Next i

    i As Integer = 0 To Chart1.Series("Series1").Points.Count - 1
    Chart1.Series(
    "Series1").Points(i).LabelFormat = "#,##0;(#,##0); "
    Next i


    Can someone get me going in the right direction?

    Thanks

Answers

  • Thursday, May 07, 2009 9:21 PM
    Owner
     
     Answer
    After further investigation I believe it is a bug in the product and double comma apprach will not work (",,"). I file a bug for this...

    Meanwile you can try this workaround to unblock you:

    Chart1.("Series1").Points.DataBind(myDataView, "Date", "Inv", "Tooltip=Variety")
    
    Chart1.("Series1").Label = "#VALY{$#,##0.00;($#,##0.00);Zero}"


    Alex.
    http://blogs.msdn.com/alexgor

All Replies

  • Thursday, April 30, 2009 1:13 AM
    Owner
     
     Proposed Answer
    Try this:

    Chart1.Series["Series1"].Points.DataBind(myReader, "Name", "Sales", "Tooltip=Year, Label=Commissions{C2}");  
    

     

    You can find more information here: http://blogs.msdn.com/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx

    Alex.


    http://blogs.msdn.com/alexgor
  • Thursday, April 30, 2009 4:37 AM
     
     Has Code
    Thanks Alex,

    I was able to get this to work:  Chart1.Series("Series1").Points.DataBind(myDataView, "Date", "Inv", "Tooltip=Variety, Label=Inv{#;(#); }")

    I would like to include the thousands separator, but can't figure out what to use.  Adding a comma throws an exception: "{#,#;(#); }"
    Trying N0 or D0 places an N or D at the beginning of the label.

    Any ideas?


  • Thursday, April 30, 2009 4:47 AM
    Owner
     
     
    Try using double commas ',,' to distingush from the separator character we use.

    Alex.
    http://blogs.msdn.com/alexgor
  • Thursday, April 30, 2009 6:52 AM
     
     

    Well, double ',,' fixed the exception, but...

    This breaks the label in the middle:  {#,,###;(#,,###); }
    This breaks the label after 1 digit: {#,,###;(#,,###); }
    This breaks the label before the last digit: {#,,0;(#,,0); }

    Chuck
  • Wednesday, May 06, 2009 3:02 PM
    Owner
     
     

    We only support what is available in the formatting string of the .NET Framework. Are you saying you canot achieve what you need with the format string or double comma approach did not work?

    Alex.


    http://blogs.msdn.com/alexgor
  • Thursday, May 07, 2009 5:58 PM
     
     

    I'm trying to supress zeros in the chart 

    I was hoping that the same format specifier used in 'chart.Series[0].LabelFormat = "$#,##0.00;($#,##0.00);Zero")";' would work.  I haven't been able to figure out another approach.  When using the double comma approach the data splits into 2 lines when displayed.

    Chuck

  • Thursday, May 07, 2009 7:18 PM
     
     

    Alex,

    I figured it out.  It takes 2 format specifiers to do it:

    Chart1.Series(
    "Series1").Points.DataBind(myDataView, "Date", "Inv", "Tooltip=Variety, Label=Inv{#}")

    and

    Chart1.Series("Series1").LabelFormat = "#"

    They both have to be there.  This will supress the zeros, though I haven't figured out how to put commas in the values.

    Chuck

  • Thursday, May 07, 2009 8:11 PM
     
     

    Or just using one specifier:

     

    Chart1.("Series1").Points.DataBind(myDataView, "Date", "Inv", "Tooltip=Variety, Label=Inv{#;(#);Zero}")

    Still no way to put in the commas...

     

  • Thursday, May 07, 2009 9:21 PM
    Owner
     
     Answer
    After further investigation I believe it is a bug in the product and double comma apprach will not work (",,"). I file a bug for this...

    Meanwile you can try this workaround to unblock you:

    Chart1.("Series1").Points.DataBind(myDataView, "Date", "Inv", "Tooltip=Variety")
    
    Chart1.("Series1").Label = "#VALY{$#,##0.00;($#,##0.00);Zero}"


    Alex.
    http://blogs.msdn.com/alexgor