I am using teechart ColorGrid series to create a color plot. The values to be plotted are whole numbers from 1 to 10. It is possible to have only few values on a plot (for example - only 1,3,5,8,9). By default the legend has ten items and the legend item values are calculated based on the minimum and maximum values (so they are not always whole numbers) and not the actual distinct values. How can I make the legend show only the distinct values which are to be plotted (1, 3, 5, 8 and 9) in this example.
I have tried to set the number of legend items by using this line of code:
tChart1.Legend.MaxNumRows = _colorGridSeries.YValues.Value.Distinct().Count();
But the legend values are still calculated as equidistant values based on the minimum and maximum values.
Some sample code:
_colorGridSeries = new ColorGrid();
tChart1.Aspect.View3D = false;
for (int x = 0; x < 10; x++)
{
for (int z = 0; z < 5; z++)
{
_colorGridSeries.Add(x, 1, z);
}
}
for (int x = 0; x < 10; x++)
{
for (int z = 5; z < 7; z++)
{
_colorGridSeries.Add(x, 5, z);
}
}
for (int x = 0; x < 10; x++)
{
for (int z = 7; z < 10; z++)
{
_colorGridSeries.Add(x, 8, z);
}
}
tChart1.Legend.MaxNumRows = _colorGridSeries.YValues.Value.Distinct().Count();
Thanks
The easiest way is probably to hide the main series from the legend (ShowInLegend=false
) and add as many dummy series as items you want to be shown in the legend, setting the appropriate color and title for each.