locked
Subscript and Superscript in Titles, labels, etc. RRS feed

  • Question

  • Has anyone figured out a way to display superscript and/or subscript characters within a chart's titles or labels? 
    Wednesday, December 3, 2008 6:04 PM

Answers

  • It can be done using fonts supporting unicode subscript and superscript characters. You can find examples on internet on how to do that. From the chart perspective you just select font and provide unicode characters to draw.

    Alex.
    Thursday, December 4, 2008 5:59 AM

All replies

  • It can be done using fonts supporting unicode subscript and superscript characters. You can find examples on internet on how to do that. From the chart perspective you just select font and provide unicode characters to draw.

    Alex.
    Thursday, December 4, 2008 5:59 AM
  •  Thanks for the response.  I've got it working now.  The key for me was finding the right font that supported the various superscript/subscript characters I wanted to display.
    Thursday, December 4, 2008 7:24 PM
  • Hi...

    I was doing same kind of thing.

    Like: I have some text painting on the form,

    eg. xxxxxxTM

    In the above eg. I want to make "TM" as Superscript.

    Can you please provide me the source code for this.

    I am using C#, Win. Mobile 6.0,Visual Studio 2008

    Thank you in advance.

     

    -Manju

    Tuesday, May 4, 2010 12:29 PM
  • do you ever get answer to this?  I am trying same. Tried with no success.  It is subscript "2" I want but if I saw TM might be able to work it out. Thanks
    Monday, April 16, 2012 2:10 PM
  • Here is how I implemented the unicode swap to allow me to have the Axis in a Log plot display as 10^x.

    I use the Chart_Customize to check if the chart's axes isLogarithmic:

        Public Sub Chart_Customize(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim chart As Chart = CType(sender, Chart)
            For Each axes As Axis In chart.ChartAreas(0).Axes
                If axes.IsLogarithmic Then
                    axes.LabelStyle.Font = New Font("Arial Unicode MS", 13)
                    Dim AxisLabels As CustomLabelsCollection = axes.CustomLabels
                    For cnt As Integer = 0 To AxisLabels.Count - 1
                        'Change the Labels to have a superscripted format... 10^x
                        AxisLabels(cnt).Text = "10" + PlottingHelpers.NumbertoSuperScriptedUnicode(Math.Log10(CDbl(AxisLabels(cnt).Text)), axes.LabelStyle.Format)
                    Next
                Else
                    'Reset the Chart Font
                    axes.LabelStyle.Font = New Font("Microsoft Sans Serif", 10)
                End If
    
            Next
        
        End Sub

    Then the PlottingHelpers.NumbertoSuperScriptedUnicode function is as follows, note this only converts numbers to Superscript, but it's enough for me:

            Public Function NumbertoSuperScriptedUnicode(NumToConvert As Double, Optional Format As String = "") As String
                Dim strToConvert = NumToConvert.ToString(Format)
                Dim UnicodeSuperscriptConversion As New Dictionary(Of String, String) From
                                                               {{"0", ChrW(&H2070)},
                                                                {"1", ChrW(&HB9)},
                                                                {"2", ChrW(&HB2)},
                                                                {"3", ChrW(&HB3)},
                                                                {"4", ChrW(&H2074)},
                                                                {"5", ChrW(&H2075)},
                                                                {"6", ChrW(&H2076)},
                                                                {"7", ChrW(&H2077)},
                                                                {"8", ChrW(&H2078)},
                                                                {"9", ChrW(&H2079)},
                                                                {".", ChrW(&HB7)},
                                                                {"-", ChrW(&H207B)}}
    
    
    
                Dim newString As String = ""
                For Each c In strToConvert
                    newString += UnicodeSuperscriptConversion(c)
                Next
                Return newString
            End Function
    
        End Module



    • Edited by Chris Zeh Monday, August 26, 2013 8:29 PM
    Thursday, August 22, 2013 8:01 PM
  • This is correct - it is font specific - BUT - be careful what versions of fonts you have. Newer operating systems have newer fonts. For example, I got the superscript to work on my dev box that is running windows 7, but it produced only squares when I published to a web server running server 2003.

    When I copied over the fonts from my Win 7 box to the Win 2003 server, it worked.

    Ultimately we decided not to use the superscripts on the chart title because deploying to other environments over which we have no control could mean that the superscripts would not appear properly.

    Thursday, September 19, 2013 8:14 PM