Marginal Abatement Curves

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
porterbe
Newbie
Newbie
Posts: 18
Joined: Wed Oct 17, 2007 12:00 am

Marginal Abatement Curves

Post by porterbe » Sun Jul 18, 2010 2:20 pm

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Marginal Abatement Curves

Post by Yeray » Mon Jul 19, 2010 9:34 am

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:

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,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

porterbe
Newbie
Newbie
Posts: 18
Joined: Wed Oct 17, 2007 12:00 am

Re: Marginal Abatement Curves

Post by porterbe » Wed Jul 21, 2010 2:33 pm

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
Attachments
MACCPlot1.jpg
MACC Plot image
MACCPlot1.jpg (148.36 KiB) Viewed 5599 times

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Marginal Abatement Curves

Post by Yeray » Thu Jul 22, 2010 6:59 pm

Hi Bernie,
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)
You could reposition your marks manually doing something like this:

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;
            }
        }
Bernie wrote:and can I make the callout wrap onto multiple lines wihout changing the source text?
You can use OnGetSeriesMark doing somethink similar to this:

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,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

porterbe
Newbie
Newbie
Posts: 18
Joined: Wed Oct 17, 2007 12:00 am

Re: Marginal Abatement Curves

Post by porterbe » Fri Jul 23, 2010 6:50 am

Wonderful, thanks.

I'm out of the office at the moment, but I'll try it when I get back in.

Bernie

porterbe
Newbie
Newbie
Posts: 18
Joined: Wed Oct 17, 2007 12:00 am

Re: Marginal Abatement Curves

Post by porterbe » Mon Aug 30, 2010 4:24 pm

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Marginal Abatement Curves

Post by Yeray » Tue Aug 31, 2010 12:53 pm

Hi Bernie,

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;
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)?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply