Page 1 of 1
Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 8:11 am
by 15670445
Hi,
1) How do I get the legend to span the entire ChartRect.Height? as shown in the attached graphs, it only spans the top of the chart?
2) How do I format the legend text so that it becomes - for instance - 128,6 instead of 128,577 ??
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 8:50 am
by narcis
Hi Friis,
1. What about something like this?
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Series.Add(new ColorGrid()).FillSampleValues();
tChart1.GetLegendRect += tChart1_GetLegendRect;
tChart1.Legend.Symbol.Continous = true;
tChart1.Legend.Font.Size = 14;
}
void tChart1_GetLegendRect(object sender, GetLegendRectEventArgs e)
{
Rectangle chartRect = this.tChart1.Chart.ChartRect;
e.Rectangle = new Rectangle(e.Rectangle.Left, chartRect.Top, e.Rectangle.Width, chartRect.Height);
}
2. You can modify legend text format in the GetLegenText event, for example:
Code: Select all
void tChart1_GetLegendText(object sender, GetLegendTextEventArgs e)
{
double tmp = Convert.ToDouble(e.Text);
e.Text = tmp.ToString("0.000");
}
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 9:09 am
by 15670445
Hi,
1) This does not solve the problem - try to test the code I have made below on your system - can you reproduce the problem?
2) Thank you - I will use this
Code: Select all
public Form1()
{
InitializeComponent();
Make3DGraph();
}
public void Make3DGraph()
{
try
{
this.tChart1.Series.Clear();
this.tChart1.Series.RemoveAllSeries();
this.tChart1.Dock = DockStyle.Fill;
this.tChart1.BackColor = Color.White;
this.tChart1.Walls.Back.Gradient.Visible = false;
this.tChart1.Walls.Back.Color = Color.White;
this.tChart1.Walls.Bottom.Gradient.Visible = false;
this.tChart1.Walls.Bottom.Color = Color.White;
this.tChart1.Panel.Gradient.Visible = false;
this.tChart1.Panel.Color = Color.White;
this.tChart1.Aspect.View3D = false;
this.tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
this.tChart1.Axes.Left.Automatic = true;
this.tChart1.Axes.Bottom.Automatic = true;
this.tChart1.Axes.Left.Title.Caption = "";
this.tChart1.Axes.Bottom.Title.Caption = "";
this.tChart1.Header.Text = "";
this.tChart1.Header.Font.Size = 14;
this.tChart1.Legend.VertSpacing = 0;
this.tChart1.Legend.Symbol.Width = 100;
this.tChart1.Legend.Transparent = false;
this.tChart1.Legend.Symbol.DefaultPen = false;
this.tChart1.Legend.Symbol.Continous = true;
this.tChart1.Legend.Symbol.Pen.Color = Color.White;
this.tChart1.Legend.Symbol.Pen.Width = 1;
this.tChart1.Legend.DividingLines.Visible = false;
this.tChart1.Legend.Symbol.Width = 50;
this.tChart1.Legend.Symbol.Squared = true;
this.tChart1.Legend.Visible = true;
this.tChart1.Legend.Shadow.Visible = true;
this.tChart1.Legend.Font.Size = 14;
this.tChart1.Axes.Left.Title.Text = "Power / MW";
this.tChart1.Axes.Left.Title.Font.Size = 14;
this.tChart1.Axes.Bottom.Title.Text = "Q / MJ/s";
this.tChart1.Axes.Bottom.Title.Font.Size = 14;
Steema.TeeChart.Styles.ColorGrid ColorGridSeries1 = new Steema.TeeChart.Styles.ColorGrid(tChart1.Chart);
this.tChart1.Series.Add(ColorGridSeries1);
ColorGridSeries1.Pen.Visible = false;
ColorGridSeries1.Title = "surface1";
ColorGridSeries1.UseColorRange = false;
ColorGridSeries1.UsePalette = true;
ColorGridSeries1.IrregularGrid = true;
ColorGridSeries1.CenteredPoints = true;
for (double x = 0; x < 10; x += 0.1) // = 10 rows
for (double z = 0; z < 10; z += 0.1) // = 10 columns
ColorGridSeries1.Add(x, x*z, z);
ColorGridSeries1.Pen.Visible = false;
ColorGridSeries1.UsePalette = true;
Color[] ColorPalette = new Color[100];
double[] ColorSteps;
ColorPalette = SetColorPalette(1, out ColorSteps);
for (int i = 0; i < ColorPalette.Length; i++)
ColorGridSeries1.AddPalette(ColorSteps[i], ColorPalette[i]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private Color[] SetColorPalette(byte Index, out double[] ColorSteps)
{
double max;
double min;
Color[] ColorPalette = new Color[100];
ColorSteps = new double[100];
ColorSteps[0] = 0;
ColorPalette[0] = Color.White;
for (int i = 1; i < 100; i++)
ColorPalette[i] = CoolColorCode(i);
for (int i = 1; i < ColorPalette.Length; i++)
ColorSteps[i] = i;
return ColorPalette;
}
private void tChart1_GetLegendRect(object sender, Steema.TeeChart.GetLegendRectEventArgs e)
{
Rectangle chartRect = this.tChart1.Chart.ChartRect;
e.Rectangle = new Rectangle(e.Rectangle.Left, chartRect.Top, e.Rectangle.Width, chartRect.Height);
}
private Color CoolColorCode(double ColorValue)
{
ColorValue = 100 - ColorValue;
if (ColorValue < 0)
ColorValue = 0;
else if (ColorValue > 100)
ColorValue = 100;
if (ColorValue < 25)
return Color.FromArgb(255, Convert.ToInt16(ColorValue / 25 * 255), 0);
else if (ColorValue < 50)
return Color.FromArgb(Convert.ToInt16(255 - ((ColorValue - 25) / 25 * 255)), 255, 0);
else if (ColorValue < 75)
return Color.FromArgb(0, 255, Convert.ToInt16((ColorValue - 50) / 25 * 255));
else
return Color.FromArgb(0, Convert.ToInt16(255 - Math.Round((ColorValue - 75) / 25 * 255)), 255);
}
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 9:21 am
by 15670445
1) Perhaps I'm not explaining the problem well enough. The blue squared symbol with a value of 15.175 in the attached image "unknown.jpeg" - I would like to have that moved down to the very bottom and the red squared symbol with a value of 128.577 to stay at the top. In that way do make the legend values show a larger range of values and colors
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 9:56 am
by narcis
Hi Friis,
1. This highly depends on the chart size. Another variable you can throw into the mix is
Legend.VertSpacing:
Code: Select all
this.tChart1.Legend.VertSpacing = 10;
You can make those values relative to the chart height.
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 10:40 am
by 15670445
Hi Narcis,
OK, vertspacing makes it look a little better...
But, for instance, in the attached image "unknown.jpeg" there are 10 symbols ranging from 0 to 128.577 - isn't it possible to increase this number to a larger number so that you accomplish a smoother gradient and larger gradient?
for instance, in the attached image "untitled.jpg" the legend is very smooth and there are an "unlimited" amounts of symbols ??
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 11:12 am
by narcis
Hi Friis,
You'd better use LegendPalette tool for that. You'll find an example at "All Features\Welcome !\Tools\Legend Palette" in the features demo available at TeeChart's program group. This applied to your example:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
this.tChart1.Series.Clear();
this.tChart1.Series.RemoveAllSeries();
this.tChart1.Dock = DockStyle.Fill;
this.tChart1.BackColor = Color.White;
this.tChart1.Walls.Back.Gradient.Visible = false;
this.tChart1.Walls.Back.Color = Color.White;
this.tChart1.Walls.Bottom.Gradient.Visible = false;
this.tChart1.Walls.Bottom.Color = Color.White;
this.tChart1.Panel.Gradient.Visible = false;
this.tChart1.Panel.Color = Color.White;
this.tChart1.Aspect.View3D = false;
this.tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
this.tChart1.Axes.Left.Automatic = true;
this.tChart1.Axes.Bottom.Automatic = true;
this.tChart1.Axes.Left.Title.Caption = "";
this.tChart1.Axes.Bottom.Title.Caption = "";
this.tChart1.Header.Text = "";
this.tChart1.Header.Font.Size = 14;
this.tChart1.Legend.VertSpacing = 0;
this.tChart1.Legend.Symbol.Width = 100;
this.tChart1.Legend.Transparent = false;
this.tChart1.Legend.Symbol.DefaultPen = false;
this.tChart1.Legend.Symbol.Continous = true;
this.tChart1.Legend.Symbol.Pen.Color = Color.White;
this.tChart1.Legend.Symbol.Pen.Width = 1;
this.tChart1.Legend.DividingLines.Visible = false;
this.tChart1.Legend.Symbol.Width = 50;
this.tChart1.Legend.Symbol.Squared = true;
this.tChart1.Legend.Visible = true;
this.tChart1.Legend.Shadow.Visible = true;
this.tChart1.Legend.Font.Size = 14;
this.tChart1.Legend.VertSpacing = 10;
this.tChart1.Axes.Left.Title.Text = "Power / MW";
//this.tChart1.Axes.Left.Title.Font.Size = 14;
this.tChart1.Axes.Bottom.Title.Text = "Q / MJ/s";
//this.tChart1.Axes.Bottom.Title.Font.Size = 14;
Steema.TeeChart.Styles.ColorGrid ColorGridSeries1 = new Steema.TeeChart.Styles.ColorGrid(tChart1.Chart);
this.tChart1.Series.Add(ColorGridSeries1);
ColorGridSeries1.Pen.Visible = false;
ColorGridSeries1.Title = "surface1";
ColorGridSeries1.UseColorRange = false;
ColorGridSeries1.UsePalette = true;
ColorGridSeries1.IrregularGrid = true;
ColorGridSeries1.CenteredPoints = true;
for (double x = 0; x < 10; x += 0.1) // = 10 rows
for (double z = 0; z < 10; z += 0.1) // = 10 columns
ColorGridSeries1.Add(x, x * z, z);
ColorGridSeries1.Pen.Visible = false;
ColorGridSeries1.UsePalette = true;
Color[] ColorPalette = new Color[100];
double[] ColorSteps;
ColorPalette = SetColorPalette(1, out ColorSteps);
for (int i = 0; i < ColorPalette.Length; i++)
ColorGridSeries1.AddPalette(ColorSteps[i], ColorPalette[i]);
legendPalette1 = new LegendPalette(tChart1.Chart);
legendPalette1.Series = ColorGridSeries1;
tChart1.Legend.Visible = false;
tChart1.GetAxesChartRect += tChart1_GetAxesChartRect;
tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels;
tChart1.Panel.MarginRight = legendPalette1.Width + 10;
}
private Steema.TeeChart.Tools.LegendPalette legendPalette1;
void tChart1_GetAxesChartRect(object sender, GetAxesChartRectEventArgs e)
{
legendPalette1.PositionUnits = PositionUnits.Pixels;
legendPalette1.Top = e.AxesChartRect.Top;
legendPalette1.Left = e.AxesChartRect.Right + 5;
legendPalette1.Height = e.AxesChartRect.Height;
}
private Color[] SetColorPalette(byte Index, out double[] ColorSteps)
{
Color[] ColorPalette = new Color[100];
ColorSteps = new double[100];
ColorSteps[0] = 0;
ColorPalette[0] = Color.White;
for (int i = 1; i < 100; i++)
ColorPalette[i] = CoolColorCode(i);
for (int i = 1; i < ColorPalette.Length; i++)
ColorSteps[i] = i;
return ColorPalette;
}
private Color CoolColorCode(double ColorValue)
{
ColorValue = 100 - ColorValue;
if (ColorValue < 0)
ColorValue = 0;
else if (ColorValue > 100)
ColorValue = 100;
if (ColorValue < 25)
return Color.FromArgb(255, Convert.ToInt16(ColorValue / 25 * 255), 0);
else if (ColorValue < 50)
return Color.FromArgb(Convert.ToInt16(255 - ((ColorValue - 25) / 25 * 255)), 255, 0);
else if (ColorValue < 75)
return Color.FromArgb(0, 255, Convert.ToInt16((ColorValue - 50) / 25 * 255));
else
return Color.FromArgb(0, Convert.ToInt16(255 - Math.Round((ColorValue - 75) / 25 * 255)), 255);
}
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 12:28 pm
by 15670445
Hi,
That looks MUCH better - Thank you
However, if I set the
Code: Select all
legendPalette1.Transparent = false;
this looks strange - the font at the legend palette looks bold ??
Re: Legend with Continous = true and formatting of legind text
Posted: Fri Oct 17, 2014 1:56 pm
by narcis
Hi Friis,
This looks like a bug to me. I have added it (
ID971) to the bug list to be fixed for future releases.
Re: Legend with Continous = true and formatting of legind text
Posted: Sun Oct 26, 2014 7:53 pm
by 15670445
Hi Again,
How do I add a title to the legendPalette?
The following code does not work?
Code: Select all
legendPalette1.title.text = "sasasf";
and
Code: Select all
legendPalette1.chart.header.text = "dsf";
just adds a title to the chart itself ?
Re: Legend with Continous = true and formatting of legind text
Posted: Mon Oct 27, 2014 9:33 am
by Christopher
NarcĂs wrote:This looks like a bug to me. I have added it (
ID971) to the bug list to be fixed for future releases.
Yes; in the meantime, a simple workaround is this:
Code: Select all
private void InitializeChart()
{
tChart1.Series.Add(new ColorGrid()).FillSampleValues();
Steema.TeeChart.Tools.LegendPalette legendPalette1 = new LegendPalette(tChart1.Chart);
legendPalette1.Series = tChart1[0];
legendPalette1.Axes.Chart.Graphics3D.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
legendPalette1.Transparent = true;
}
Re: Legend with Continous = true and formatting of legind text
Posted: Mon Oct 27, 2014 9:38 am
by Christopher
Friis wrote:just adds a title to the chart itself ?
Try:
Code: Select all
legendPalette1.Axes.Chart.Header.Visible = true;
legendPalette1.Axes.Chart.Header.Text = "asasas";
Re: Legend with Continous = true and formatting of legind text
Posted: Mon Oct 27, 2014 9:47 am
by 15670445
Just implemented both of the solutions you have presented here - it works fantastic both of them - thank you