Hi
Apologies if this has been answered elsewhere - there's no search results for Marginal...
I need to generate a Marginal Abatement Curve plot for an application I am developing, and was hoping that TeeChart would allow me to do so. If you are not sure what one of these is (I needed to look it up!), there's a brief explanation here http://en.wikipedia.org/wiki/Marginal_Abatement_Cost.
I was thinking that I could use a BarChart series fed with an array of values to give the hights, and then control the width of each bar based on an array of X values. My questions are i) is this possible, ii) is this the best way to do it & iii) how do I control the width of each bar individually?
I'm only a novice with TeeChart - it's worked fine for me so far (but then the most complex I've got is to put 3 seperate series on 3 seperate Y axis on the same chart and X axis), so any and all help appreciated.
BTW, I suppose I should say I'm also quite behind the times in that I'm using VS2005, C# & TeeChart V3.5.3498 on XP Pro.
Once again thanks in advance for the help.
Bernie
Marginal Abatement Curves
Re: Marginal Abatement Curves
Hi Bernie,
I think you could use Bar series with BarWidthPercent = 100. With this property each bar rectangle width is determined for the next bar XValue.
So you have to give to each bar X value its antecedent's bar width. Here is an example:
I think you could use Bar series with BarWidthPercent = 100. With this property each bar rectangle width is determined for the next bar XValue.
So you have to give to each bar X value its antecedent's bar width. Here is an example:
Code: Select all
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
int numBars = 6;
double[] widths = new double[numBars];
double[] heights = new double[numBars];
Random r = new Random();
for (int i = 0; i < numBars; i++)
{
widths[i] = r.Next(10) + 2;
if (i == 0) heights[i] = -r.Next(10);
else heights[i] = heights[i-1] + r.Next(5);
}
Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.BarWidthPercent = 100;
for (int i = 0; i < numBars; i++)
{
if (i == 0) bar1.Add(i, heights[i]);
else bar1.Add(bar1.XValues[i-1] + widths[i-1], heights[i]);
}
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Marginal Abatement Curves
Ok, thanks for that - it seems to work sort of....
I've attached an image of what's being output - my question now is how can I get the callout labels to line up with the appropriate bar (the Paralell Hybrid is the long bar at the LHS), and can I make the callout wrap onto multiple lines wihout changing the source text?
Once again, thanks for the prompt response, and for the future help...
Bernie
I've attached an image of what's being output - my question now is how can I get the callout labels to line up with the appropriate bar (the Paralell Hybrid is the long bar at the LHS), and can I make the callout wrap onto multiple lines wihout changing the source text?
Once again, thanks for the prompt response, and for the future help...
Bernie
- Attachments
-
- MACC Plot image
- MACCPlot1.jpg (148.36 KiB) Viewed 5600 times
Re: Marginal Abatement Curves
Hi Bernie,
You could reposition your marks manually doing something like this:Bernie wrote:I've attached an image of what's being output - my question now is how can I get the callout labels to line up with the appropriate bar (the Paralell Hybrid is the long bar at the LHS)
Code: Select all
private void RecalcMarkPositions()
{
tChart1.Draw();
for (int i = 0; i < bar1.Marks.Positions.Count-1; i++)
{
Steema.TeeChart.Styles.SeriesMarks.Position mp1 = bar1.Marks.Positions[i];
mp1.Custom = true;
int middle = bar1.CalcXPos(i) + ((tChart1.Axes.Bottom.CalcXPosValue(widths[i]) - tChart1.Axes.Bottom.CalcXPosValue(0)) / 2);
mp1.LeftTop.X = middle - (int)(tChart1.Graphics3D.TextWidth(bar1.YValues[i].ToString())/ 2) - 4;
mp1.ArrowFix = false;
mp1.ArrowTo.X = middle;
mp1.ArrowFrom.X = middle;
}
}
You can use OnGetSeriesMark doing somethink similar to this:Bernie wrote:and can I make the callout wrap onto multiple lines wihout changing the source text?
Code: Select all
void bar1_GetSeriesMark(Steema.TeeChart.Styles.Series series, Steema.TeeChart.Styles.GetSeriesMarkEventArgs e)
{
e.MarkText = e.MarkText.Substring(0, 10) + "\n" + e.MarkText.Substring(10, e.MarkText.Length-10);
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Marginal Abatement Curves
Wonderful, thanks.
I'm out of the office at the moment, but I'll try it when I get back in.
Bernie
I'm out of the office at the moment, but I'll try it when I get back in.
Bernie
Re: Marginal Abatement Curves
Well that all seemed to work, thanks for the help.
I have another question now - coming from the same plot but likely a different issue so if you want me to start another thread, then just say so.
I have had to add a dummy data element to get the last bar to display the correct width. This now appears in the legend. What I'd like to do is remove the last entry from the legend - I can get the last legend's text, but I can't stop the whole thing from showing.
Any ideas?
TIA,
Bernie
I have another question now - coming from the same plot but likely a different issue so if you want me to start another thread, then just say so.
I have had to add a dummy data element to get the last bar to display the correct width. This now appears in the legend. What I'd like to do is remove the last entry from the legend - I can get the last legend's text, but I can't stop the whole thing from showing.
Any ideas?
TIA,
Bernie
Re: Marginal Abatement Curves
Hi Bernie,
If the elements in the legend are series, you can hide any of them with the ShowInLegend property:
If you only have a series, it won't be easy to delete a row from the legend. If that's the case could you please explain why do you have an extra value (with a simple example we can run as-is to reproduce the problem here if possible)?
If the elements in the legend are series, you can hide any of them with the ShowInLegend property:
Code: Select all
tChart1[tChart1.Series.Count-1].ShowInLegend = false;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |