Left axis titles displayed but all series unchecked

TeeChart for ActiveX, COM and ASP
Post Reply
PascalL
Newbie
Newbie
Posts: 13
Joined: Mon May 15, 2006 12:00 am

Left axis titles displayed but all series unchecked

Post by PascalL » Tue Jul 09, 2013 10:52 am

Hi,
I create line series added in legend with checkbox and title in left axis using custom axes. When all series or few series are selected, the relevant left axis titles are shown as expected i.e. only the titles of the selected series. But when all series are unselected, all the left axis titles are displayed (see the attached screens copy). Could you help me to avoid this?
Many thanks in advance.
Pascal
(Teechart2013.ocx is in use)
Attachments
TChart 2013 - Legend with checkbox.zip
(354.8 KiB) Downloaded 907 times

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Left axis titles displayed but all series unchecked

Post by Yeray » Tue Jul 09, 2013 3:01 pm

Hi Pascal,

You could implement some logic in the OnClickLegend event to hide all the axes when no series is visible. For example, this seems to work fine for me here:

Code: Select all

Private Sub TChart1_OnClickLegend(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
  Dim showAxes As Boolean
  showAxes = False

  Dim i As Integer
  For i = 0 To TChart1.SeriesCount - 1
    If TChart1.Series(i).Active Then
      showAxes = True
      Exit For
    End If
  Next i
  
  For i = 0 To TChart1.Axis.CustomCount - 1
    TChart1.Axis.Custom(i).Visible = showAxes
  Next i
End Sub
Here it is the rest of the code I used to test the above:

Code: Select all

Private Sub Form_Load()
  TChart1.Aspect.View3D = False
  
  TChart1.Panel.MarginLeft = 7
  TChart1.Legend.CheckBoxes = True

  Dim i, nSeries As Integer
  nSeries = 4
  For i = 0 To nSeries - 1
    TChart1.AddSeries scLine
    TChart1.Series(i).FillSampleValues 5
    TChart1.Series(i).VerticalAxisCustom = TChart1.Axis.AddCustom(False)
    With TChart1.Axis.Custom(i)
      .AxisPen.Color = TChart1.Series(i).Color
      .Title.Caption = "Custom " & Str$(i)
      .Title.Angle = 90
      .Title.Font.Color = TChart1.Series(i).Color
      .PositionUnits = puPixels
      .StartPosition = i * 100 / nSeries
      .EndPosition = (i + 1) * 100 / nSeries
    End With
  Next i
End Sub
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

PascalL
Newbie
Newbie
Posts: 13
Joined: Mon May 15, 2006 12:00 am

Re: Left axis titles displayed but all series unchecked

Post by PascalL » Tue Jul 09, 2013 3:52 pm

Hi Yeray,

Thank you for this nice answer. What about using this event callback with VS C++ ?

FYI, we use some events in the following way:

Code: Select all

BEGIN_EVENTSINK_MAP(CResult, CDialog)
    //{{AFX_EVENTSINK_MAP(CResult)
	ON_EVENT(CResult, IDC_TCHART1, 37 /* OnMarkTipToolGetText */, OnMarkTipToolGetTextTchart1, VTS_I4 VTS_PBSTR)
	ON_EVENT(CResult, IDC_TCHART1, 19 /* OnMouseDown */, OnMouseDownTchart, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
	ON_EVENT(CResult, IDC_TCHART1, 21 /* OnMouseUp */, OnMouseUpTchart, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
	ON_EVENT(CResult, IDC_TCHART1, 201 /* OnMouseEnterSeries */, OnMouseEnterSeriesTchart1, VTS_I4)
	ON_EVENT(CResult, IDC_TCHART1, 202 /* OnMouseLeaveSeries */, OnMouseLeaveSeriesTchart1, VTS_I4)
	ON_EVENT(CResult, IDC_TCHART1, 20 /* OnMouseMove */, OnMouseMoveTchart1, VTS_I4 VTS_I4 VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
but I can't find where this code comes from.

Pascal

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

Re: Left axis titles displayed but all series unchecked

Post by Sandra » Thu Jul 11, 2013 3:50 pm

Hello Pascal,

The easiest way to achieve add Event using VS c++ is adding Event OnClickLegend in design time following next steps:
1.- Open Design time dialog and select the Chart.
2.- Click with right button and choose Events
3.- Select OnClickLegend event and add it.
4.- After do it, event is created automatically and added in the code.

The code should be similar as next:

Code: Select all

// TestLabelsC6Dlg.cpp : implementation file
#include "stdafx.h"
#include "TestLabelsC6.h"
#include "TestLabelsC6Dlg.h"
#include "panel.h"
#include "series.h"
#include "axes.h"
#include "axis.h"
#include "TeeChartDefines.h"
#include "aspect.h"
#include "zoom.h"
#include "scroll.h"
#include "environment.h"
#include "marks.h"
#include "page.h"
#include "lineseries.h"
#include "fastlineseries.h"
#include "surfaceseries.h"
#include "colorgridseries.h"
#include "mappolygon.h"
#include "mapseries.h"
#include "mappolygonlist.h" 
#include "axisarrowtool.h"
#include "toollist.h"
#include "tools.h"
#include "legendpalettetool.h"
#include "comutil.h"
#include "afxdisp.h"
#include "pen.h"
#include "legend.h"
#include "legendsymbol.h"
#include "marksitem.h"
#include "pointarray.h"
#include "teepoint2d.h"
#include "strings.h"
#include "chartaxispen.h"
#include "axistitle.h"
#include "teefont.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestLabelsC6Dlg dialog

CTestLabelsC6Dlg::CTestLabelsC6Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestLabelsC6Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestLabelsC6Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestLabelsC6Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestLabelsC6Dlg)
	DDX_Control(pDX, IDC_BUTTON1, m_button1);
	DDX_Control(pDX, IDC_TCHART1, m_tChart1);
	DDX_Control(pDX, IDC_TEECOMMANDER1, m_TCommander);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestLabelsC6Dlg, CDialog)
	//{{AFX_MSG_MAP(CTestLabelsC6Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestLabelsC6Dlg message handlers

BOOL CTestLabelsC6Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_tChart1.ClearChart();
	m_tChart1.GetAspect().SetView3D(FALSE); 
	m_tChart1.GetPanel().SetMarginLeft(7); 
	m_tChart1.GetLegend().SetCheckBoxes(TRUE); 
	int i,nSeries; 
	nSeries=4; 

	for(i=0; i<nSeries; i++)
	{
		m_tChart1.AddSeries(scLine); 
		m_tChart1.Series(i).FillSampleValues(5); 
		m_tChart1.Series(i).SetVerticalAxisCustom(m_tChart1.GetAxis().AddCustom(FALSE));
	    m_tChart1.GetAxis().GetCustom(i).GetAxisPen().SetColor(m_tChart1.Series(i).GetColor()); 
		m_tChart1.GetAxis().GetCustom(i).GetTitle().SetCaption("Custom"); 
		m_tChart1.GetAxis().GetCustom(i).GetTitle().SetAngle(90); 
		m_tChart1.GetAxis().GetCustom(i).GetTitle().GetFont().SetColor(m_tChart1.Series(i).GetColor()); 
		m_tChart1.GetAxis().GetCustom(i).SetPositionUnits(puPixels); 
		m_tChart1.GetAxis().GetCustom(i).SetStartPosition(i * 100 / nSeries); 
		m_tChart1.GetAxis().GetCustom(i).SetEndPosition((i + 1) * 100 / nSeries);
 
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestLabelsC6Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTestLabelsC6Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestLabelsC6Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestLabelsC6Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	//long i = m_tChart1.Series(0);
	m_tChart1.ShowEditor(0);
}

BEGIN_EVENTSINK_MAP(CTestLabelsC6Dlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CTestLabelsC6Dlg)
	ON_EVENT(CTestLabelsC6Dlg, IDC_TCHART1, 6 /* OnClickLegend */, OnOnClickLegendTchart1, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
	ON_EVENT(CTestLabelsC6Dlg, IDC_TCHART1, 253 /* OnAddSeries */, OnOnAddSeriesTchart1, VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CTestLabelsC6Dlg::OnOnClickLegendTchart1(long Button, long Shift, long X, long Y) 
{
	// TODO: Add your control notification handler code here
	bool showAxes=FALSE; 
	int i; 
	for(i=0; i<m_tChart1.GetSeriesCount(); i++)
	{
		if(m_tChart1.Series(i).GetActive())
		{
			showAxes=TRUE; 
			
		}
	}
	for(i=0; i<m_tChart1.GetAxis().GetCustomCount(); i++)
	{
		m_tChart1.GetAxis().GetCustom(i).SetVisible(showAxes); 
	}
	

}
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

PascalL
Newbie
Newbie
Posts: 13
Joined: Mon May 15, 2006 12:00 am

Re: Left axis titles displayed but all series unchecked

Post by PascalL » Fri Jul 12, 2013 7:07 am

Hi Sandra,

Thank you for this nice help. I feel I got all what I need.
Have a great day.

Best regards,
Pascal

Post Reply