Hello Phil
Thanks for information. Basically, your problem is that BarWidht property doesn't work in correct way in version 2 and it breaks your application. If you want achieve the same results than latest version TeeChartFor.Net 2012 I recommend use CustomBarWidth property as I do in next code:
Code: Select all
//Version 2.
double TotalSum;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Walls.Back.Visible = false;
tChart1.Axes.Left.Grid.Visible = false;
Steema.TeeChart.Styles.Bar Series1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
TotalSum = 0;
for (int i = 0; i < 5; i++)
{
Series1.Add(i, i * 100 + 5);
TotalSum = TotalSum + Series1.YValues[i];
}
//InitializeSeries.
Series1.MultiBar = MultiBars.SelfStack;
Series1.BarStyle = BarStyles.RectGradient;
Series1.VertAxis = VerticalAxis.Both;
Series1.Marks.Visible = false;
Series1.CustomBarWidth = tChart1.Width;
SetCustomLabels();
}
private void SetCustomLabels()
{
double NewPosition = 0;
Steema.TeeChart.Styles.Bar bar1 = (tChart1[0] as Steema.TeeChart.Styles.Bar);
for (int i = 0; i < bar1.Count; i++)
{
NewPosition = NewPosition + bar1.YValues[i];
tChart1.Axes.Left.Labels.Items.Add(NewPosition, (Math.Round(bar1.YValues[i] * 100 / TotalSum, 2)).ToString() + "%");
}
NewPosition = 0;
for (int i = 0; i < bar1.Count; i++)
{
NewPosition = NewPosition + tChart1[0].YValues[i];
tChart1.Axes.Right.Labels.Items.Add(NewPosition, (bar1.XValues[i] * 100 / 10).ToString() + "%");
}
}
private void button3_Click(object sender, EventArgs e)
{
tChart1.ShowEditor();
}
Could you tell us if previous code works in your end?
Lastly, is it possible to set the colour of the bars individually?
Yes, is possible. You can assign a color for each bar point. I have added a list of colors in my previous code that allow you assign one color for each bar point:
Code: Select all
double TotalSum;
List<Color> colorList;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Walls.Back.Visible = false;
tChart1.Axes.Left.Grid.Visible = false;
Steema.TeeChart.Styles.Bar Series1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
colorList = new List<Color>(new Color[] { Color.Red, Color.Green, Color.Blue, Color.HotPink, Color.Black});
TotalSum = 0;
for (int i = 0; i < 5; i++)
{
Series1.Add(i, i * 100 + 5,colorList[i]);
TotalSum = TotalSum + Series1.YValues[i];
}
//InitializeSeries.
Series1.MultiBar = MultiBars.SelfStack;
Series1.BarStyle = BarStyles.RectGradient;
Series1.VertAxis = VerticalAxis.Both;
Series1.Marks.Visible = false;
Series1.CustomBarWidth = tChart1.Width;
SetCustomLabels();
}
private void SetCustomLabels()
{
double NewPosition = 0;
Steema.TeeChart.Styles.Bar bar1 = (tChart1[0] as Steema.TeeChart.Styles.Bar);
for (int i = 0; i < bar1.Count; i++)
{
NewPosition = NewPosition + bar1.YValues[i];
tChart1.Axes.Left.Labels.Items.Add(NewPosition, (Math.Round(bar1.YValues[i] * 100 / TotalSum, 2)).ToString() + "%");
}
NewPosition = 0;
for (int i = 0; i < bar1.Count; i++)
{
NewPosition = NewPosition + tChart1[0].YValues[i];
tChart1.Axes.Right.Labels.Items.Add(NewPosition, (bar1.XValues[i] * 100 / 10).ToString() + "%");
}
}
private void button3_Click(object sender, EventArgs e)
{
tChart1.ShowEditor();
}
Could you tell us if previous code works in your end?
I hope will helps.
Thanks,