Labels on CandleBar series issue on zoom
Posted: Thu May 24, 2012 3:02 pm
I have an issue where the bottom axis label is not being displayed correctly when chart is zoomed and candle style is CandleBar. I am trying to only display month-year on the bottom axis. The GetAxisLabel method works correctly when chart is unzoomed, but when zoomed GetAxisLabel is not called for every e.ValueIndex. If I change the candle style to Line, then the GetAxisLabel method is called for each e.ValueIndex.
How do I get the GetAxisLabel method to be called for each e.ValueIndex when the candle style is CandleBar?
How do I get the GetAxisLabel method to be called for each e.ValueIndex when the candle style is CandleBar?
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Steema.TeeChart.TChart chart = new Steema.TeeChart.TChart();
public Form1()
{
InitializeComponent();
chart.Parent = this;
chart.Dock = DockStyle.Fill;
chart.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(chart_GetAxisLabel);
chart.Panel.MarginBottom = 10;
chart.Legend.Visible = false;
chart.Aspect.View3D = false;
Panel panel = new Panel();
panel.Height = 50;
panel.Parent = this;
panel.Dock = DockStyle.Top;
Button btnChange = new Button();
btnChange.Click += new EventHandler(btnChange_Click);
btnChange.Parent = panel;
btnChange.Top = 10;
btnChange.Left = 10;
btnChange.Text = "Change Type";
FillChart(chart);
}
void chart_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
{
if (e.ValueIndex != -1)
{
DateTime lDate = DateTime.FromOADate(e.Series[e.ValueIndex].X);
if (e.ValueIndex == 0)
e.LabelText = "";
else
{
DateTime lPrevDate = DateTime.FromOADate(e.Series[e.ValueIndex].X - 1);
if (lPrevDate.Month != lDate.Month)
e.LabelText = lDate.Month.ToString() + "-" + lDate.Year.ToString();
else
e.LabelText = "";
}
}
}
void btnChange_Click(object sender, EventArgs e)
{
Steema.TeeChart.Styles.Candle series = (Steema.TeeChart.Styles.Candle)chart.Series[0];
if (series.Style == Steema.TeeChart.Styles.CandleStyles.CandleBar)
series.Style = Steema.TeeChart.Styles.CandleStyles.Line;
else
series.Style = Steema.TeeChart.Styles.CandleStyles.CandleBar;
}
void FillChart(Steema.TeeChart.TChart chart)
{
chart.Series.Clear();
Steema.TeeChart.Styles.Candle lCandle = new Steema.TeeChart.Styles.Candle(chart.Chart);
lCandle.Style = Steema.TeeChart.Styles.CandleStyles.CandleBar;
lCandle.UpCloseColor = Color.Black;
lCandle.DownCloseColor = Color.Black;
lCandle.FillSampleValues(10000);
lCandle.XValues.DateTime = false;
lCandle.Visible = true;
lCandle.Title = "OHLC";
for (int i = 0; i < lCandle.Count; i++)
{
lCandle[i].Label = i.ToString();
}
chart.Refresh();
chart.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Text;
chart.Axes.Bottom.Labels.Separation = 0;
chart.Axes.Bottom.Labels.Angle = 90;
}
}
}