Up to 60 points it's working:
But for example for 70 points (when labels start to overlap each other) - chart itself performs labels thinning (my function Bottom_GetAxisDrawLabel is disabled here):
Up to 60 points it's working:
Code: Select all
public partial class Form1 : Form
{
//max visible labels
private const Int32 maxDisplayedLabelsForBottomaAxis = 20;
List<string> _labels = new List<string>();
int _count;
public Form1()
{
var rnd = new Random();
InitializeComponent();
tChart1.Zoomed += TChart1_Zoomed;
tChart1.UndoneZoom += TChart1_UndoneZoom;
tChart1.AfterDraw += TChart1_AfterDraw;
_count = 4000;
for (int i = 0; i < _count; i++)
{
line1.Add(i, rnd.Next(5));
_labels.Add($"Point NoClue #{rnd.Next()}");
if (ShouldDrawIndex(i, 0, _count))
{
tChart1.Axes.Bottom.Labels.Items.Add(i, _labels[i]);
}
}
}
private void TChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
this.Text = $"Number of labels = {tChart1.Axes.Bottom.Labels.Items.Count}";
}
private void TChart1_UndoneZoom(object sender, EventArgs e)
{
tChart1.Axes.Bottom.Labels.Items.Clear();
for (int i = 0; i < _count; i++)
{
if (ShouldDrawIndex(i, 0, _count))
{
tChart1.Axes.Bottom.Labels.Items.Add(i, _labels[i]);
}
}
}
private bool ShouldDrawIndex(int index, int firstVisible, int lastVisible)
{
if ((lastVisible - firstVisible) > maxDisplayedLabelsForBottomaAxis)
{
var drawEvery = ((lastVisible - 1 - firstVisible) / maxDisplayedLabelsForBottomaAxis) + 1;
return index % drawEvery == 0;
}
return true;
}
private void TChart1_Zoomed(object sender, EventArgs e)
{
tChart1.Axes.Bottom.Labels.Items.Clear();
var xvalues = line1.XValues.Value.Where((x, i) => i < _count);
var min = line1.XValues.IndexOf(xvalues.Where(x => x >= tChart1.Axes.Bottom.Minimum).First());
var max = line1.XValues.IndexOf(xvalues.Where(x => x <= tChart1.Axes.Bottom.Maximum).Last());
for (int i = min; i <= max; i++)
{
if(ShouldDrawIndex(i, min, max))
{
tChart1.Axes.Bottom.Labels.Items.Add(i, _labels[i]);
}
}
}
}
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
So we've finally returned to using Zoomed and UndoneZoom events Looks like it's working now, many thanks.Christopher wrote: ↑Tue Aug 13, 2019 7:58 amokay, well, another variation on an earlier technique seems to work in these circumstances, i.e.
Code: Select all
var xvalues = line1.XValues.Value.Where((x, i) => i < _count);
You're welcome.
The Value field is public but is for internal use. If you are uncomfortable using it, you can use the more standard API calls:
Code: Select all
List<double> xvalues = new List<double>();
for (int i = 0; i < _count; i++)
{
xvalues.Add(line1.XValues[i]);
}
//var xvalues = line1.XValues.Value.Where((x, i) => i < _count);
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |