Setting the location of bar graph labels!

TeeChart for ActiveX, COM and ASP
Post Reply
Seth
Newbie
Newbie
Posts: 25
Joined: Mon Aug 02, 2004 4:00 am

Setting the location of bar graph labels!

Post by Seth » Fri Nov 12, 2004 2:54 am

Hello, I am a V6 user.
Let's say that we have a bar graph. It has different length of bars and I want to show their values on top of each bar.
I know I can set the distance between the values and the top of bars. And, I also know that I can move the values up and down.
What if I want to position the labels in the middle of each bar? I couldn't find any option for this one.
I have many requests about this option so I hope there is some way to do this.
Thanks.

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Nov 12, 2004 12:08 pm

Hi Seth,

you can do this using the following code :

Code: Select all

Private Sub Form_Load()
With TChart1
    .AddSeries scBar
    .Series(0).FillSampleValues (5)
    .Series(0).Marks.Visible = True
    .Aspect.View3D = False
    .Environment.InternalRepaint
    For i = 0 To .Series(0).Count - 1
       BarTop = .Series(0).CalcYPos(i)
       BarBottom = .Series(0).CalcYPosValue(0)
       ypos = (BarTop + BarBottom) / 2
       .Series(0).Marks.Positions.Position(i).Custom = True
       .Series(0).Marks.Positions.Position(i).LeftTop.Y = ypos
    Next i
End With
End Sub

Seth
Newbie
Newbie
Posts: 25
Joined: Mon Aug 02, 2004 4:00 am

Post by Seth » Thu Dec 23, 2004 9:38 am

Hello again with this problem!
The problem seems to be solved alright until I found another thick wall.
First to mention, we have 2 charts. Each chart has number of series. One of chart has a series which contains null value.
Now, please have a look at this piece of code.

Code: Select all

BOOL CTeeFilesView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
 
 if (!CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
  return FALSE;
 
 //WS_CHILD | WS_VISIBLE
 //Create TeeChart - sized to Client window afterwards with 'OnSize'
 if (!m_Chart1.Create(lpszClassName, 
       "", 
       dwStyle, 
       CRect(0,0,50,50), 
       this, 
       IDC_TCHART1, 
       pContext))
  return FALSE;
 DeltaRot = 4;
 DeltaElev = 3;
 DeltaZoom = 5;
 m_Chart1.SetVisible(true);
   m_Chart1.ClearChart();
 m_Chart1.AddSeries(scBar);
   m_Chart1.AddSeries(scBar);
   m_Chart1.AddSeries(scBar);
 
   m_Chart1.Series(0).GetAsBar().SetMultiBar(mbStacked);
 
   m_Chart1.Series(0).AddNull("");
   m_Chart1.Series(0).AddNull("");
   m_Chart1.Series(1).AddNull("");
   m_Chart1.Series(1).AddNull("");
   m_Chart1.Series(2).AddNull("");
   m_Chart1.Series(2).AddNull("");
 

   m_Chart1.Series(0).SetPointLabel(0, "aaa");
   m_Chart1.Series(0).SetPointValue(0, 10);
   m_Chart1.Series(0).SetPointColor(0, RGB(244,0,39));
   m_Chart1.Series(0).SetPointLabel(1, "bbb");
   m_Chart1.Series(0).SetPointValue(1, 20);
   m_Chart1.Series(0).SetPointColor(1, RGB(244,0,39));
   
   
   m_Chart1.Series(1).SetPointValue(0, 15);
   m_Chart1.Series(1).SetPointLabel(0, "aaa");
   m_Chart1.Series(1).SetPointColor(0, RGB(24,0,239));
   m_Chart1.Series(1).SetPointValue(1, 30);
   m_Chart1.Series(1).SetPointLabel(1, "bbb");
   m_Chart1.Series(1).SetPointColor(1, RGB(24,0,239));
 
   m_Chart1.Series(2).SetPointValue(1, 14);
   m_Chart1.Series(2).SetPointLabel(1, "bbb");
   m_Chart1.Series(2).SetPointColor(1, RGB(0,130,39));
   
  
   double BarTop, BarBottom, ypos, moffset;
   int seriesCnt = m_Chart1.GetSeriesCount();            
   m_Chart1.GetEnvironment().InternalRepaint();
 
   for(int i=0; i<seriesCnt; i++) {
      int num = m_Chart1.Series(i).GetCount();
 
      for(int j=0; j<num; j++) {
         BarTop = m_Chart1.Series(i).CalcYPos(j);
         if(i > 0) 
            BarBottom = m_Chart1.Series(i-1).CalcYPos(j);
         else                     
            BarBottom = m_Chart1.Series(i).CalcYPosValue(0);
                  
         if(m_Chart1.Series(i).IsNull(j)) {            
            continue;
         }
         
         m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).SetCustom(TRUE);
         ypos=BarBottom-(50/100.0)*(BarBottom-BarTop);
         moffset = m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).GetHeight();
         ypos -= moffset;
         ypos += (moffset/2);               
                     
         m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).GetLeftTop().SetY(ypos);
      }
   }
 
   m_Chart1.GetExport().SaveToFile("C:\\aaaa.tmp");
 return true;
}
Since this code came from your example, I am pretty sure you recognize this well.

Basically, the problem is the chart program being dead.
This occurs when.....

1. "m_Chart1.Series(i)" is null. (with no if block inside the for loop)
This case, the program crashes when ,m_Chart1.Series(i).GetMarks().GetPositions().GetPosition(j).SetCustom(TRUE);,
this line is executing.

2. So, if I check the nullity of "m_Chart1.Series(i)", and put "continue" like how thigs are done above.
This case, the program crashes when ,m_Chart1.GetExport().SaveToFile("C:\\aaaa.tmp");, line is executing.

Asking about this in the first place was because we have a customer who want us to show this function on chart. Hence, having this problem would cause a lot of trouble.

I hope you can find the solution to this. Thanks.

Seth
Newbie
Newbie
Posts: 25
Joined: Mon Aug 02, 2004 4:00 am

Post by Seth » Tue Dec 28, 2004 8:23 am

Hello again.
It has been a while and the reply is still not posted yet.
I can only imagine that you are busy or this question is classified as "hard-to-anwer" but the thing is we have customers who use tee-chart and complain about the bugs.
It's very important for us to notify our customers the expected date of the patch or the schedule to make one.
As we consider this problem as critical, we think you should at least tell us what you are doing.
We are disappointed that none of problems related to bugs are resolved yet.


- chart bug (containing a null series being dead, as discussed on this post)
- tooltip bug
http://209.68.2.74/stee/support/modules ... c2b577694a
- guage chart line bug
http://209.68.2.74/stee/support/modules ... 4c309f3f5d

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Dec 28, 2004 10:46 am

Hi Seth,

sorry for delay, I've been able to reproduce it here and we're investigating which which could be the problem. I'll back to you with results as soon as possible.

Post Reply