Bar Chart. Changing the Legend Display

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Bar Chart. Changing the Legend Display

Post by Dave » Tue Jul 14, 2015 4:09 pm

Hi, Please see the attached bar chart screenshot. Its a basic bar chart. Ive attached the code below that I used to create it.
Id like to change the display in the following ways;

1) The legend simply display "bar1". Instead Id like to have a legend that displays the value of each bar. eg.

SYNC = 23333
CFD = 2323
TAC = 12122
ADC = 568768

Is this possible?

2) The Y-axis exponential labelling is almost OK. However instead of "1.0*10+7" Id like to just have "10+7".
ie. How do I remove the preceding "1.0". Ive tried changing the ValueFormat for the left axis label but I am not getting what I want.

3) Finally how do I make the bars be closer together?

Thanks.

Dave


--------------------------------------------------------------------

ratesChart.Aspect.View3D = false;
ratesChart.Axes.Left.Labels.Exponent = true;
ratesChart.Axes.Left.Labels.ValueFormat = "#.0•10 E+0";
ratesChart.Axes.Left.Logarithmic = true;
ratesChart.Legend.Visible = true;

bar1 = new Steema.TeeChart.Styles.Bar(ratesChart.Chart);

int sync = 50000;
int cfd = 60000;
int tac = 55000;
int adc = 44000;

bar1.Add(sync, "SYNC", Color.Green);
bar1.Add(cfd, "CFD", Color.Black);
bar1.Add(tac, "TAC", Color.Blue);
bar1.Add(adc, "ADC", Color.Red);

bar1.Marks.Visible = false;
bar1.BarWidthPercent = 30;
Attachments
barChart.PNG
Bar Chart with default Legend
barChart.PNG (7.09 KiB) Viewed 9244 times

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Bar Chart. Changing the Legend Display

Post by Christopher » Wed Jul 15, 2015 8:36 am

Hello Dave,

I think the lines of code at the bottom of this example should go some way to resolving your three issues:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      tChart1.Axes.Left.Labels.Exponent = true;
      //tChart1.Axes.Left.Labels.ValueFormat = "#.0•10 E+0";
      tChart1.Axes.Left.Logarithmic = true;
      tChart1.Legend.Visible = true;

      Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);

      int sync = 50000;
      int cfd = 60000;
      int tac = 55000;
      int adc = 44000;

      bar1.Add(sync, "SYNC", Color.Green);
      bar1.Add(cfd, "CFD", Color.Black);
      bar1.Add(tac, "TAC", Color.Blue);
      bar1.Add(adc, "ADC", Color.Red);

      bar1.Marks.Visible = false;
      bar1.BarWidthPercent = 30;

      tChart1.Axes.Bottom.MaximumOffset = 100;
      tChart1.Axes.Bottom.MinimumOffset = 100;

      tChart1.Legend.LegendStyle = LegendStyles.Values;
      tChart1.Axes.Left.Labels.ValueFormat = "##E+0";
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Re: Bar Chart. Changing the Legend Display

Post by Dave » Tue Jul 28, 2015 1:43 pm

Christopher
Thanks that has helped a lot. Ive attached a image of what my chart looks like now.

As you can see the Y-axis looks better but its not quite right. Ideally I'd like to replace the initial "1" with "10" because that's what is being represented.
ie. its actually "1*10+6" NOT "1+6". So if I could just display "10+6" it would be ideal. Ive tried playing about with the format but I cannot get it to do this.

The legend on the right is good. Im happy with it. However it would be even better if the values could be shown in floating point, not very large integers as is being displayed. Is there an easy way to do this.

Thanks again.
Attachments
chart.PNG
chart with legend
chart.PNG (10.73 KiB) Viewed 9182 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Bar Chart. Changing the Legend Display

Post by Narcís » Thu Jul 30, 2015 11:05 am

Hi Dave,
Dave wrote: As you can see the Y-axis looks better but its not quite right. Ideally I'd like to replace the initial "1" with "10" because that's what is being represented.
ie. its actually "1*10+6" NOT "1+6". So if I could just display "10+6" it would be ideal. Ive tried playing about with the format but I cannot get it to do this.
That's how it looks like using Christopher's code with latest TeeChart version available. Just pasting it into a new WinForms application with a TChart component on it gives me this chart:
dave.jpg
dave.jpg (43.39 KiB) Viewed 9152 times
Dave wrote: The legend on the right is good. Im happy with it. However it would be even better if the values could be shown in floating point, not very large integers as is being displayed. Is there an easy way to do this.
Yes, adding the line below to the code snippet above solves the problem.

Code: Select all

      bar1.ValueFormat = "##E+0";
Best Regards,
Narcís Calvet / 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