Page 1 of 1

Bar Chart. Changing the Legend Display

Posted: Tue Jul 14, 2015 4:09 pm
by 13050364
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;

Re: Bar Chart. Changing the Legend Display

Posted: Wed Jul 15, 2015 8:36 am
by Christopher
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";
    }

Re: Bar Chart. Changing the Legend Display

Posted: Tue Jul 28, 2015 1:43 pm
by 13050364
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.

Re: Bar Chart. Changing the Legend Display

Posted: Thu Jul 30, 2015 11:05 am
by narcis
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 9154 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";