I have a chart with two bar graphs (one is for positive values and enother is for negative):
I have only values below 5 and above 1000, so I tried to use logarithmic axis. But negative values are not possible for that axis type.
So I ask for help: i there any way to draw log(X) graph for first bar graph and -log(X) for second one?
I mean that I want to have a chart like picture above but with logarithmic left axis.
Logarithmic axis and negaive values
Logarithmic axis and negaive values
Thank you.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Logarithmic axis and negaive values
Hi bairog,
No, logarithm doesn't support negative values:
http://en.wikipedia.org/wiki/Logarithm# ... lex_number
Complex logarithm scaling is not supported in TeeChart.
Having said that, the only solution I can think of is that you use 2 axes, one for the positive part and another one for the negative part. I recommend you to read tutorial 4 for further axis setting information. You could use an inverted logarithmic axis for the negative part, adding log labels to each point when populating them and add the "-" symbol using the GetAxisLabel event or already adding it with the points labels.
Hope this helps!
No, logarithm doesn't support negative values:
http://en.wikipedia.org/wiki/Logarithm# ... lex_number
Complex logarithm scaling is not supported in TeeChart.
Having said that, the only solution I can think of is that you use 2 axes, one for the positive part and another one for the negative part. I recommend you to read tutorial 4 for further axis setting information. You could use an inverted logarithmic axis for the negative part, adding log labels to each point when populating them and add the "-" symbol using the GetAxisLabel event or already adding it with the points labels.
Hope this helps!
Best Regards,
Narcís Calvet / 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: Logarithmic axis and negaive values
Well, taking into account printing, scrolling and zooming i suppose that the easiest way is to do the following operations:
1) use a chart with non-logarithmic left axis
2) add log(x) instead of positive values that >= 10, -log(|X|) instead of negative values that <= -10, X/10 instead all others
3) recalculate left axis labels using GetAxisLabel event
4) replace series marks text with original values using GetSeriesMarks
I've implemented this and everything was ok except one thing. There are duplicate left axis marks (originaly they were 0, 1, 1, 2, 2, etc):
How can I avoid duplicating left axis marks (I mean I want left axis marks to be: 0, 10, 100, 1000 etc.) automatically?
1) use a chart with non-logarithmic left axis
2) add log(x) instead of positive values that >= 10, -log(|X|) instead of negative values that <= -10, X/10 instead all others
3) recalculate left axis labels using GetAxisLabel event
4) replace series marks text with original values using GetSeriesMarks
I've implemented this and everything was ok except one thing. There are duplicate left axis marks (originaly they were 0, 1, 1, 2, 2, etc):
How can I avoid duplicating left axis marks (I mean I want left axis marks to be: 0, 10, 100, 1000 etc.) automatically?
Thank you.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Logarithmic axis and negaive values
Hi bairog,
The easiest solution I can think of is not drawing every second mark, setting it to an empty string, in the GetAxisLabel event.
The easiest solution I can think of is not drawing every second mark, setting it to an empty string, in the GetAxisLabel event.
Best Regards,
Narcís Calvet / 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: Logarithmic axis and negaive values
The situation is more difficult than you suppose. Let me show you:Narcís wrote:The easiest solution I can think of is not drawing every second mark
In this situation I should remove all labels except second in each duplicate labels sequence (second label is correct one)
In this situation I should remove all labels except third in each duplicate labels sequence (third label is correct one). Notice that last sequence (the sequence of -10000's) is shorter than all others.
Well in that case the algorithm of finding the correct label which will work in both situations to my mind is:
Code: Select all
int CorretLabelIndex = MinDuplicateLabelIndex + (MaxDuplicateLabelIndex - MinDuplicateLabelIndex) / 2
BUT:
1) I'm not sure that this algorithm will work correctly in all othes situations
2) Programming GetAxisLabel event to find all duplicate labels sequences, calculating correct label index and removing all others for each sequence in not short and trivial. I'm looking for the easiest way.
3) I supposed that such powerfull component like TeeChart has automatic mechanisms to remove duplicate labels.
BTW
Notice (if you didn't already) that I'm using "0" FormatValue for left axis labels (so they become 0, 10, 100, etc. after my manual recalculatting on step 3)
So what can you suggest me in such case?
Thank you.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Logarithmic axis and negaive values
Hi bairog,
Could you please attach a simple example project we can run "as-is" so that we can reproduce the issue here and try to find the optimal solution?
An alternative could be using custom labels as in the All Features\Welcome!\Axes\Labels\Custom labels example in the features demo available at TeeChart's program group.
Thanks in advance.
Could you please attach a simple example project we can run "as-is" so that we can reproduce the issue here and try to find the optimal solution?
An alternative could be using custom labels as in the All Features\Welcome!\Axes\Labels\Custom labels example in the features demo available at TeeChart's program group.
Thanks in advance.
Best Regards,
Narcís Calvet / 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: Logarithmic axis and negaive values
Do you mean you need an example that can show both situations described above?Narcís wrote:Could you please attach a simple example project we can run "as-is" so that we can reproduce the issue here and try to find the optimal solution?
Ok, here it is.
Due to maximum file size limitations there are two arhives: program and teeChart.dll I was using.
- Attachments
-
- WindowsApplication3.7z
- (79.06 KiB) Downloaded 555 times
-
- TeeChart.7z
- (510.91 KiB) Downloaded 623 times
Thank you.
Re: Logarithmic axis and negaive values
Hi bairog,
Could you please take a look at this proposal?
Could you please take a look at this proposal?
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Bar bar1, bar2;
private void InitializeChart()
{
chartController1.Chart = tChart1;
tChart1.Aspect.View3D = false;
tChart1.Legend.Visible = false;
bar1 = new Bar(tChart1.Chart);
bar2 = new Bar(tChart1.Chart);
bar1.MultiBar = MultiBars.Stacked;
tChart1.Axes.Left.MinorTicks.Visible = false;
tChart1.Axes.Left.Labels.Items.Clear();
tChart1.Axes.Left.Labels.Items.Add(0);
bar1.Add(1 / 10.0);
bar2.Add(-1 / 10.0);
tChart1.Axes.Left.Labels.Items.Add(1 / 10.0, "1");
tChart1.Axes.Left.Labels.Items.Add(-1 / 10.0, "-1");
AddLog(bar2, -1000);
AddLog(bar2, -10);
AddLog(bar2, -10000);
bar1.GetSeriesMark += new Series.GetSeriesMarkEventHandler(bar1_GetSeriesMark);
bar2.GetSeriesMark += new Series.GetSeriesMarkEventHandler(bar1_GetSeriesMark);
}
private void AddLog(Bar bar, double p)
{
if (p > 0)
{
bar.Add(Math.Log10(p));
tChart1.Axes.Left.Labels.Items.Add(bar.YValues.Value[bar.Count - 1], p.ToString());
}
else
{
bar.Add(-Math.Log10(Math.Abs(p)));
tChart1.Axes.Left.Labels.Items.Add(bar.YValues.Value[bar.Count - 1], p.ToString());
}
}
private void bar1_GetSeriesMark(Steema.TeeChart.Styles.Series series, Steema.TeeChart.Styles.GetSeriesMarkEventArgs e)
{
if (series == bar1)
e.MarkText = "1";
else
if (e.ValueIndex == 0)
e.MarkText = "-1";
else
if (e.ValueIndex == 1)
e.MarkText = "-1000";
else
if (e.ValueIndex == 2)
e.MarkText = "-10";
else
e.MarkText = "-10000";
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |