percentage mark on the Y- axis

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
mikethelad
Newbie
Newbie
Posts: 58
Joined: Thu Jul 05, 2012 12:00 am

percentage mark on the Y- axis

Post by mikethelad » Fri Sep 14, 2012 8:31 am

How do I add a percentage mark on the Y- axis
Attachments
graph.JPG
graph.JPG (49.29 KiB) Viewed 7308 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: percentage mark on the Y- axis

Post by Sandra » Fri Sep 14, 2012 9:47 am

Hello mikethelad,

To achieve the percentage in the Y-axis, you only need change the style of the axes to get the style of Marks. You can do something as next lines of code:

Code: Select all

   Series1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Percent;
           tChart1.Axes.Left.Labels.Style = AxisLabelStyle.Mark;
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

mikethelad
Newbie
Newbie
Posts: 58
Joined: Thu Jul 05, 2012 12:00 am

Re: percentage mark on the Y- axis

Post by mikethelad » Fri Sep 14, 2012 10:24 am

I only getting one % value if I do this, see example
Attachments
graph.JPG
graph.JPG (23.66 KiB) Viewed 7268 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: percentage mark on the Y- axis

Post by Sandra » Fri Sep 14, 2012 11:53 am

Hello mikethelad,

In this case, the option is use GetAxisDrawLabel event of left axis as I do in next simple code where I have modified the text label adding a percentage:

Code: Select all

       public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private void InitializeChart()
        {
            double MaxX, MinX;
            tChart1.Aspect.View3D = false;
            tChart1.Dock = DockStyle.Fill;
            tChart1.Legend.Alignment = LegendAlignments.Bottom;

            for (int i = 0; i < 2; i++)
            {
                new Steema.TeeChart.Styles.Line(tChart1.Chart);
                tChart1[i].FillSampleValues(2);
                tChart1[i].Marks.Visible = true;
                tChart1[i].Marks.Style = Steema.TeeChart.Styles.MarksStyles.Percent;
            }
            tChart1.Axes.Left.GetAxisDrawLabel += new GetAxisDrawLabelEventHandler(Left_GetAxisDrawLabel);
            tChart1.Axes.Bottom.MaximumOffset = 2;
            tChart1.Axes.Bottom.MinimumOffset = 1;
            tChart1.Axes.Left.MaximumOffset = 2;
            tChart1.Axes.Left.MinimumOffset = 1;
        }

        void Left_GetAxisDrawLabel(object sender, GetAxisDrawLabelEventArgs e)
        {
            e.Text = e.Text + "%";
        }
Can you tell if previous code works as you want?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

mikethelad
Newbie
Newbie
Posts: 58
Joined: Thu Jul 05, 2012 12:00 am

Re: percentage mark on the Y- axis

Post by mikethelad » Fri Sep 14, 2012 3:34 pm

Nearly, the 100% is being choppied to 00%, I have tried increasing the offset to 15


WebChart1.Chart.Axes.Left.MinimumOffset = 15;
WebChart1.Chart.Axes.Left.MaximumOffset = 15;
Attachments
graph.JPG
graph.JPG (38.49 KiB) Viewed 7256 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: percentage mark on the Y- axis

Post by Sandra » Mon Sep 17, 2012 9:34 am

Hello mikethelad,

I can try to reproduce your problem but it not occurs for me using last version of TeeChartFor.Net and next code:

Code: Select all

    Steema.TeeChart.Chart tChart1;

    protected void Page_Load(object sender, EventArgs e)
    {
        tChart1 = WebChart3.Chart;
        InitializeChart();

    }
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
 
            tChart1.Legend.Alignment = LegendAlignments.Bottom;

            for (int i = 0; i < 2; i++)
            {
                new Steema.TeeChart.Styles.Line(tChart1.Chart);
                tChart1[i].Marks.Visible = true;
                AddValues(tChart1[i], 2);
                tChart1[i].Marks.Style = Steema.TeeChart.Styles.MarksStyles.Percent;
            }

            tChart1.Axes.Left.GetAxisDrawLabel += new GetAxisDrawLabelEventHandler(Left_GetAxisDrawLabel);
            tChart1.Axes.Bottom.MaximumOffset = 2;
            tChart1.Axes.Bottom.MinimumOffset = 1;
            tChart1.Axes.Left.MaximumOffset = 15;
            tChart1.Axes.Left.MinimumOffset = 15;
            tChart1.Axes.Left.SetMinMax(0, 100);
        }
        private void AddValues(Steema.TeeChart.Styles.Series s, int value)
        {
            Random rnd = new Random();
            for (int i = 0; i < value; i++)
            {
                s.Add(i, rnd.Next(100));
            }
        }
        void Left_GetAxisDrawLabel(object sender, GetAxisDrawLabelEventArgs e)
        {
            e.Text = e.Text + "%";
        }
Please see previous code and check if your problem occurs using it. If occurs, please can you tell us which version of TeeChart are you using?

On the other hand, seeing your image seems the 100% doesn't appear, because the margin is slimmer than default margin of WebChart. If is the case, I recommend you change the size of your margin left as I do in next line of code, because the labels can draw correctly:

Code: Select all

  tChart1.Panel.MarginLeft = 10;
Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply