Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Hi Steema Support Team,
I'm using Steema Silverlight version. I need to put Y Axis Values(Left Axis) in consaistent dp format.
i.e. if Values on Left Axis are 0, 0.5, 1, 1.5 and 2 Then they should be displayed on Y Axis like 0.0, 0.5, 1.0, 1.5, 2.0
similarly
if Values on Left Axis are 0, 0.05, 0.1, 0.15,0.2,0.25,0.3 Then they should be displayed on Y Axis like 0, 0.05, 0.10, 0.15,0.20,0.25,0.30
So number of decimal palces in LabelFormat should be dynamic. So basically I want to calculate valueformat at run time on the basis of Left Axis values.
TeeChart.Axes.Left.Labels.ValueFormat="0.0"
TeeChart.Axes.Left.Labels.ValueFormat="0.00"
TeeChart.Axes.Left.Labels.ValueFormat="0.000"
I tried it by using TeeChart.Axes.Left.CalcIncrement property but its not returning the correct increment value unless the chart is drawn.
I'm using Steema Silverlight version. I need to put Y Axis Values(Left Axis) in consaistent dp format.
i.e. if Values on Left Axis are 0, 0.5, 1, 1.5 and 2 Then they should be displayed on Y Axis like 0.0, 0.5, 1.0, 1.5, 2.0
similarly
if Values on Left Axis are 0, 0.05, 0.1, 0.15,0.2,0.25,0.3 Then they should be displayed on Y Axis like 0, 0.05, 0.10, 0.15,0.20,0.25,0.30
So number of decimal palces in LabelFormat should be dynamic. So basically I want to calculate valueformat at run time on the basis of Left Axis values.
TeeChart.Axes.Left.Labels.ValueFormat="0.0"
TeeChart.Axes.Left.Labels.ValueFormat="0.00"
TeeChart.Axes.Left.Labels.ValueFormat="0.000"
I tried it by using TeeChart.Axes.Left.CalcIncrement property but its not returning the correct increment value unless the chart is drawn.
- Attachments
-
- DP Format.PNG (36.95 KiB) Viewed 22999 times
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Hello Neelam,
Ok. If you want a specific increment, you need modify the Increment of left axis as do in next example code:
Can you tell us if previous code works as you want?
I hope will helps.
Ok. If you want a specific increment, you need modify the Increment of left axis as do in next example code:
Code: Select all
public MainPage()
{
InitializeComponent();
InitializeChart();
}
Steema.TeeChart.Silverlight.Styles.Line Series1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Series1 = new Steema.TeeChart.Silverlight.Styles.Line(tChart1.Chart);
Series1.Add(0, 0.05);
Series1.Add(1, 0.1);
Series1.Add(2, 0.15);
Series1.Add(3, 0.2);
Series1.Add(4, 0.25);
Series1.Add(5, 0.30);
tChart1.Axes.Left.Increment = 0.05;
}
I hope will helps.
Best Regards,
Sandra Pazos / 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 |
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Points to the series are getting added at run time and I don't know the Increment Value. It can be 0.5 or 0.05 or 0.005. So on the basis of Increment value I need to set the LabelFormat of Y Axius values. So the format can be anyone of the following:
TeeChart.Axes.Left.Labels.ValueFormat="0.0"
TeeChart.Axes.Left.Labels.ValueFormat="0.00"
TeeChart.Axes.Left.Labels.ValueFormat="0.000"
Is there anyway I can get the value of TeeChart.Axes.Left.CalcIncrement property before Chart_Drwa event?
TeeChart.Axes.Left.Labels.ValueFormat="0.0"
TeeChart.Axes.Left.Labels.ValueFormat="0.00"
TeeChart.Axes.Left.Labels.ValueFormat="0.000"
Is there anyway I can get the value of TeeChart.Axes.Left.CalcIncrement property before Chart_Drwa event?
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Hello Neelam,
I suggest you do something us next code, where I have used a TextBox to get its value and after I have set to Labels ValueFormat:
Can you tell us if previous code works as you want? If it doesn't work as you want, please explain exactly, what you want do code
Thanks,
I suggest you do something us next code, where I have used a TextBox to get its value and after I have set to Labels ValueFormat:
Code: Select all
public MainPage()
{
InitializeComponent();
InitializeChart();
}
Steema.TeeChart.Silverlight.Styles.Line Series1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Series1 = new Steema.TeeChart.Silverlight.Styles.Line(tChart1.Chart);
Series1.Add(0, 0.05);
Series1.Add(1, 0.1);
Series1.Add(2, 0.15);
Series1.Add(3, 0.2);
Series1.Add(4, 0.25);
Series1.Add(5, 0.30);
tChart1.Axes.Left.Increment = 0.05;
textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged);
}
void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
tChart1.Axes.Left.Labels.ValueFormat = textBox1.Text;
if (tChart1.Axes.Left.Labels.ValueFormat == "0.0")
{
tChart1.Axes.Left.Increment = 0.5;
}
else if (tChart1.Axes.Left.Labels.ValueFormat == "0.00")
{
tChart1.Axes.Left.Increment = 0.05;
}
else if (tChart1.Axes.Left.Labels.ValueFormat == "0.000")
{
tChart1.Axes.Left.Increment = 0.005;
}
}
Thanks,
Best Regards,
Sandra Pazos / 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 |
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
I need to use TeeChart.Axes.Left.CalcIncrement property. But its returning wrong value. TeeChart.Axes.Left.CalcIncrement property returns correct value once the chart is drawn. That is it returns correct value TeeChart_AfterDraw event. Is there any way to get this value before draw method.
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Hello Neelam,
The chart must be drawn before calculate increment of axes, so need the series values to calculate its increment correctly. The only way occurs me to achieve as you want is assign manually the increment.
Thanks,
The chart must be drawn before calculate increment of axes, so need the series values to calculate its increment correctly. The only way occurs me to achieve as you want is assign manually the increment.
Thanks,
Best Regards,
Sandra Pazos / 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 |
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
As mentioned TeeChart.Axes.Left.CalcIncrement can give correct value only after chart is drawn. So If I need to set the Labels.ValueFormat on the basis of CalcIncrement property I write the following code. Its working fine but I'm getting 1 issue here that chart Axis Label values get overlapped. Plz refer the screenshot. Is there any way that Axis is cleared or not get overlapped if we redrwaing the Axis.
private void tChart_AfterDraw(object sender, Steema.TeeChart.Silverlight.Drawing.Graphics3D g)
{
var vm = (ReportsViewModel)DataContext;
if (vm != null)
{
tChart.Axes.Left.Labels.ValueFormat = YAxisFormat(tChart.Axes.Left.CalcIncrement);
tChart.Axes.Draw();
}
}
private void tChart_AfterDraw(object sender, Steema.TeeChart.Silverlight.Drawing.Graphics3D g)
{
var vm = (ReportsViewModel)DataContext;
if (vm != null)
{
tChart.Axes.Left.Labels.ValueFormat = YAxisFormat(tChart.Axes.Left.CalcIncrement);
tChart.Axes.Draw();
}
}
- Attachments
-
- DPIssue.PNG (23.84 KiB) Viewed 22853 times
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Hello Neelam,
Could you send us a simple project so we can reproduce exactly your problem here and try to find a good solution for you?
Thanks,
Could you send us a simple project so we can reproduce exactly your problem here and try to find a good solution for you?
Thanks,
Best Regards,
Sandra Pazos / 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 |
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Hi,
I've attached only XAML/Xaml.cs files as size was getting larger than the allowed limit.
Problem#1: If you click on the first, second & third button you will see the overlapping issue of Axis labels.
As I don’t know what will be the incremental gap at the time of adding points to the Chart, I used the .Axes.Left.CalcIncrement property in the AfterDraw Event. I set the format of Y Axis and called the Axis.Draw method
Problem#2: If you click the Left Right Axis issue you will notice that we have different Bottom Axis for Left & Right Axis. Is it possible that I can have common Bottom Axis for Left & Right Axis. Refer the attached image(LeftRightAxisIssue.png). Also refer the output I want(its possible in Windows.NET Silverlight version) DesiredLeftRightAxis.PNG
Thanks,
Neelam
I've attached only XAML/Xaml.cs files as size was getting larger than the allowed limit.
Problem#1: If you click on the first, second & third button you will see the overlapping issue of Axis labels.
As I don’t know what will be the incremental gap at the time of adding points to the Chart, I used the .Axes.Left.CalcIncrement property in the AfterDraw Event. I set the format of Y Axis and called the Axis.Draw method
Problem#2: If you click the Left Right Axis issue you will notice that we have different Bottom Axis for Left & Right Axis. Is it possible that I can have common Bottom Axis for Left & Right Axis. Refer the attached image(LeftRightAxisIssue.png). Also refer the output I want(its possible in Windows.NET Silverlight version) DesiredLeftRightAxis.PNG
Thanks,
Neelam
- Attachments
-
- DesiredLeftRightAxis.PNG (26.47 KiB) Viewed 22808 times
-
- LeftRightAxisIssue.PNG (57.81 KiB) Viewed 22822 times
-
- SteemaChartSampleApplication.zip
- (1.95 KiB) Downloaded 1179 times
Re: Dynamic number of Decimal Places in Axes.Left.Labels.ValueFo
Hello Neelam,
Can you tell us if previous code works as you expect?
I hope will helps.
Thanks,
To solve the problem I have removed Axes.Draw() from AfterDraw Event and I have set the property this.Visibility to visible and the problem disappears for me. You mus add the property in the method DrawChart() as do in next lines of cod:I've attached only XAML/Xaml.cs files as size was getting larger than the allowed limit.
Problem#1: If you click on the first, second & third button you will see the overlapping issue of Axis labels.
As I don’t know what will be the incremental gap at the time of adding points to the Chart, I used the .Axes.Left.CalcIncrement property in the AfterDraw Event. I set the format of Y Axis and called the Axis.Draw method
Code: Select all
private void DrawChart()
{
SampleChart.Series.Clear(true);
Steema.TeeChart.Silverlight.Styles.Line LineSeries1;
LineSeries1 = new Steema.TeeChart.Silverlight.Styles.Line();
for (int i = 1; i <= 10; i++)
{
LineSeries1.Add(i,i * increment);
}
SampleChart.Series.Add(LineSeries1);
SetFormat = true;
MiddleAxis = false;
SampleChart.AfterDraw +=new Steema.TeeChart.Silverlight.PaintChartEventHandler(SampleChart_AfterDraw);
//Add it to redraw
this.Visibility = System.Windows.Visibility.Visible;
}
I have made a simple code that works fine for me using last version of TeeChart.Net.Problem#2: If you click the Left Right Axis issue you will notice that we have different Bottom Axis for Left & Right Axis. Is it possible that I can have common Bottom Axis for Left & Right Axis. Refer the attached image(LeftRightAxisIssue.png). Also refer the output I want(its possible in Windows.NET Silverlight version) DesiredLeftRightAxis.PNG
Code: Select all
private double increment;
private bool SetFormat,MiddleAxis;
public MainPage()
{
InitializeComponent();
increment = 1;
SampleChart.Aspect.View3D = false;
SampleChart.Axes.Left.Automatic = true;
SampleChart.Axes.Left.MaximumRound = true;
SampleChart.Axes.Left.Grid.Visible = false;
SampleChart.Axes.Right.Grid.Visible = false;
SetFormat = false;
}
private void DrawChart()
{
SampleChart.Series.Clear(true);
Steema.TeeChart.Silverlight.Styles.Line LineSeries1;
LineSeries1 = new Steema.TeeChart.Silverlight.Styles.Line();
for (int i = 1; i <= 10; i++)
{
LineSeries1.Add(i,i * increment);
}
SampleChart.Series.Add(LineSeries1);
SetFormat = true;
MiddleAxis = false;
SampleChart.AfterDraw +=new Steema.TeeChart.Silverlight.PaintChartEventHandler(SampleChart_AfterDraw);
//Add it to redraw
this.Visibility = System.Windows.Visibility.Visible;
}
private void First_Click(object sender, RoutedEventArgs e)
{
increment = 0.5;
DrawChart();
}
private void Second_Click(object sender, RoutedEventArgs e)
{
increment = 0.05;
DrawChart();
}
private void Third_Click(object sender, RoutedEventArgs e)
{
increment = 0.005;
DrawChart();
}
//Determines the Label format on the basis of Incremenental gap of Y Axis
private string YAxisFormat(double Diff)
{
string sFormat="";
int i;
if (Diff >= 1)
{
return "#,##0";
}
sFormat = "0.";
for (i = 0; i <= 10; i++)
{
sFormat = sFormat + "0";
if (Diff < 1 / Math.Pow(10, i) && Diff >= 1 / Math.Pow(10, i + 1))
break;
}
return sFormat;
}
private void SampleChart_AfterDraw(object sender, Steema.TeeChart.Silverlight.Drawing.Graphics3D g)
{
if (SetFormat)
{
SetFormat = false;
SampleChart.Axes.Left.Labels.ValueFormat = YAxisFormat(SampleChart.Axes.Left.CalcIncrement);
}
string HexaColor = "#000000";
SampleChart.Graphics3D.Pen.Color =
Color.FromArgb(
Convert.ToByte("FF", 16),
Convert.ToByte(HexaColor.Substring(1, 2), 16),
Convert.ToByte(HexaColor.Substring(3, 2), 16),
Convert.ToByte(HexaColor.Substring(5, 2), 16)
);
//Control the BottomAxis position
if (MiddleAxis)
{
int posAxis = 0;
posAxis = (int)SampleChart.Axes.Left.CalcYPosValue(0);
SampleChart.Axes.Bottom.Draw(posAxis + 10, posAxis + 40, posAxis, true);
SampleChart.Axes.Bottom.Visible = false;
}
else
{
int posAxis = 0;
posAxis =(int) SampleChart.Axes.Left.IEndPos;
SampleChart.Axes.Bottom.Draw(posAxis + 10, posAxis + 40, posAxis, true);
SampleChart.Axes.Bottom.Visible = false;
}
}
private void TwoAxis_Click(object sender, RoutedEventArgs e)
{
increment = 1;
SampleChart.Series.Clear(true);
Steema.TeeChart.Silverlight.Styles.Line LeftSeries;
LeftSeries = new Steema.TeeChart.Silverlight.Styles.Line();
LeftSeries.VertAxis = Steema.TeeChart.Silverlight.Styles.VerticalAxis.Left;
Steema.TeeChart.Silverlight.Styles.Line RightSeries;
RightSeries = new Steema.TeeChart.Silverlight.Styles.Line();
RightSeries.VertAxis = Steema.TeeChart.Silverlight.Styles.VerticalAxis.Right;
for (int i = 0; i <10; i++)
{
RightSeries.Add(i, i * increment);
}
LeftSeries.Title = "Left Series";
for (int i = 0; i <5; i++)
{
LeftSeries.Add(i, i * increment);
LeftSeries.Add(i, -(i * increment));
}
RightSeries.Title = "Right Series";
SampleChart.Series.Add(LeftSeries);
SampleChart.Series.Add(RightSeries);
MiddleAxis = true;
SetFormat = false;
}
I hope will helps.
Thanks,
Best Regards,
Sandra Pazos / 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 |