Hello newbie,
I am glad that you can find a solution for your problem
. On the other hand, I have made a simple code to draw your rectangles in the BeferoDrawAxes and I think you can do something as next:
Code: Select all
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
tChart1.Aspect.View3D = false;
checkBox1.Checked = false;
tChart1.Walls.Back.Visible = false;
tChart1.Axes.Bottom.Grid.Visible = false;
tChart1.Axes.Left.Grid.Visible = false;
tChart1.Axes.Left.SetMinMax(0, 700);
tChart1.Axes.Bottom.SetMinMax(0, 10);
tChart1.BeforeDrawAxes += new Steema.TeeChart.PaintChartEventHandler(tChart1_BeforeDrawAxes);
}
private Steema.TeeChart.Styles.Bar Series1;
private void InitializeSeries()
{
Series1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
Series1.FillSampleValues(10);
tChart1.Axes.Left.SetMinMax(0, Series1.YValues.Maximum);
tChart1.Axes.Bottom.SetMinMax(0, Series1.XValues.Maximum);
tChart1.Draw();
}
void tChart1_BeforeDrawAxes(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
if (Series1 != null)
{
int x = tChart1.Axes.Bottom.CalcPosValue(0);
int w = tChart1.Axes.Bottom.CalcPosValue(tChart1.Axes.Bottom.Maximum) - x;
int y = tChart1.Axes.Left.CalcPosValue(tChart1.Axes.Left.Maximum);
int h = tChart1.Axes.Left.CalcPosValue(0) - y;
g.FillRectangle(Brushes.Tomato, 0, 0, tChart1.Width, tChart1.Height);//'Fill the entire background
g.FillRectangle(Brushes.White, x, y, w, h);// 'fill only the desired rect
}
else
{
int x = tChart1.Axes.Bottom.CalcPosValue(0);
int w = tChart1.Axes.Bottom.CalcPosValue(tChart1.Axes.Bottom.Maximum) - x;
int y = tChart1.Axes.Left.CalcPosValue(tChart1.Axes.Left.Maximum);
int h = tChart1.Axes.Left.CalcPosValue(0) - y;
g.FillRectangle(Brushes.Tomato, 0, 0, tChart1.Width, tChart1.Height);//'Fill the entire background
g.FillRectangle(Brushes.White, x, y, w, h);// 'fill only the desired rect
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
InitializeSeries();
}
else
{
tChart1.Series.Clear();
tChart1.Axes.Left.SetMinMax(0, 700);
tChart1.Axes.Bottom.SetMinMax(0, 10);
}
}
Can you tell us if previous code works fine with your values? If it doesn't works as you expect, please send us a simple project so we can adapt the solution with your data and try to find a optimal solution for you.
I hope will helps.
Thanks,