Page 1 of 1
Axes and data series
Posted: Tue Apr 27, 2010 6:09 pm
by 9644416
Hello everyone,
Questions: How can I?
1) Show in the axes bottom the each value of the data series.
2) Display the maximum and minimum value as a string in that axe?
Min valueX = 00:00:00
Max valueX = 07:59:59
Thanks you for your help.
Re: Axes and data series
Posted: Thu Apr 29, 2010 9:28 am
by 10050769
Hello tenaris,
1) Show in the axes bottom the each value of the data series.
I made a simple example, that I think you can use in your project. Please, check next code works as you want?
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.Styles.Bar bar1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Dock = DockStyle.Fill;
bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.Marks.Visible = false;
Random rnd = new Random();
DateTime today = DateTime.Today;
TimeSpan oneDay = TimeSpan.FromDays(1);
bar1.XValues.DateTime = true;
for (int i = 1; i <= 20; ++i)
{
bar1.Add(today, rnd.Next(100), Color.Red);
today += oneDay;
}
tChart1.Axes.Bottom.Labels.Items.Clear();
for (int i = 0; i <bar1.Count ; i++)
{
tChart1.Axes.Bottom.Labels.Items.Add(bar1.XValues[i], DateTime.FromOADate(bar1.XValues[i]).ToShortDateString());
}
tChart1.Axes.Bottom.Labels.Angle = 90;
tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);
}
2) Display the maximum and minimum value as a string in that axe?
Min valueX = 00:00:00
Max valueX = 07:59:59
If you want display maximum and minimum value you could do a similar code as next, using GetNextAxisLabel event. Please, see next code and check if it works as you want.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.Styles.Bar bar1;
private bool first = true;
double newValue;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Dock = DockStyle.Fill;
bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.Marks.Visible = false;
bar1.XValues.DateTime = true;
Random rnd = new Random();
for (int i = 0; i < 20; ++i)
{
bar1.Add(DateTime.Now.AddDays(i), rnd.Next(100), Color.Red);
}
tChart1.Panel.MarginBottom = 20;
tChart1.Axes.Bottom.Labels.Angle = 90;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss";
tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);
tChart1.GetNextAxisLabel += new Steema.TeeChart.GetNextAxisLabelEventHandler(tChart1_GetNextAxisLabel);
}
void tChart1_GetNextAxisLabel(object sender, Steema.TeeChart.GetNextAxisLabelEventArgs e)
{
double seriesIncrement = tChart1.Axes.Bottom.Increment;
if (sender.Equals(tChart1.Axes.Bottom))
{
e.Stop = false;
if (first)
{
newValue = e.LabelValue;
first = false;
}
else
{
newValue += seriesIncrement;
}
if (e.LabelIndex == 0)
{
e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Left.Position);
DateTime.FromOADate(e.LabelValue).ToLocalTime();
}
else
{
if (e.LabelIndex == tChart1[0].Count)
{
e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IEndPos);
DateTime.FromOADate(e.LabelValue).ToLocalTime();
}
else
{
if (e.LabelIndex < tChart1[0].Count)
{
e.LabelValue = newValue;
DateTime.FromOADate(e.LabelValue).ToLocalTime();
}
else
{
e.Stop = true;
first = true;
}
}
}
}
}
Also, if you want more examples, I recommend that see this
thread, where there are more complex examples.
I hope will helps.
Thanks,