Page 1 of 1
Logarithmic axis and negaive values
Posted: Tue Jul 14, 2009 9:17 am
by 9641771
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.
Re: Logarithmic axis and negaive values
Posted: Tue Jul 14, 2009 9:32 am
by narcis
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!
Re: Logarithmic axis and negaive values
Posted: Tue Jul 14, 2009 1:26 pm
by 9641771
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?
Re: Logarithmic axis and negaive values
Posted: Tue Jul 14, 2009 1:47 pm
by narcis
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.
Re: Logarithmic axis and negaive values
Posted: Wed Jul 15, 2009 5:33 am
by 9641771
Narcís wrote:The easiest solution I can think of is not drawing every second mark
The situation is more difficult than you suppose. Let me show you:
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
All other duplicate labels except correct one should be set to empty string (or not visible).
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?
Re: Logarithmic axis and negaive values
Posted: Wed Jul 15, 2009 1:38 pm
by narcis
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.
Re: Logarithmic axis and negaive values
Posted: Thu Jul 16, 2009 12:37 pm
by 9641771
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?
Do you mean you need an example that can show both situations described above?
Ok, here it is.
Due to maximum file size limitations there are two arhives: program and teeChart.dll I was using.
Re: Logarithmic axis and negaive values
Posted: Fri Jul 17, 2009 10:43 am
by yeray
Hi bairog,
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";
}