This is a migrated thread and some comments may be shown as answers.

Programmatically Export GanttView to File

6 Answers 154 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Yemo
Top achievements
Rank 1
Iron
Yemo asked on 17 Mar 2017, 03:05 PM

Hello,

Please advise whteher there is an available code sample on how to use the following specified method in winforms

IImageExporter..::..ExportToImage Method 

http://doc.evget.com/HelpDocument/RadControlsForWpf/html/M_Telerik_Windows_Controls_GanttView_IImageExporter_ExportToImage.htm

or any alternative routine to achieve the same desired effect.

Many thanks

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 21 Mar 2017, 11:12 AM
Hello Yemi,

Thank you for writing.

We have internal methods that can export the Gantt to an image, they are used for printing. Here is how you can use them to create an image:
class MyGantt : RadGanttView
{
    public void Export(string path)
    {
        GanttViewTraverser traverser = new GanttViewTraverser(this.GanttViewElement);
        traverser.TraverseAllItems = true;
        List<GanttViewDataItem> flatItemsCollection = new List<GanttViewDataItem>();
 
        while (traverser.MoveNext())
        {
            flatItemsCollection.Add(traverser.Current);
        }
        float height = flatItemsCollection.Count * this.ItemHeight + this.HeaderHeight;
        float width = (float)((this.GanttViewElement.GraphicalViewElement.TimelineBehavior.AdjustedTimelineEnd.AddDays(1) - this.GanttViewElement.GraphicalViewElement.TimelineBehavior.AdjustedTimelineStart).TotalSeconds /
          (float)this.GanttViewElement.GraphicalViewElement.OnePixelTime.TotalSeconds);
         
        Bitmap bmp = new Bitmap((int)width,(int)height);
        int columnsWidth = 0;
 
        foreach (GanttViewTextViewColumn col in this.Columns)
        {
            if (col.Visible)
            {
                columnsWidth += col.Width;
            }
        }
 
        this.drawArea = new RectangleF(0, 0, columnsWidth, 100);
 
        using (Graphics grp = Graphics.FromImage(bmp))
        {
            grp.FillRectangle( Brushes.White, 0, 0, bmp.Width, bmp.Height);
        }
 
        this.DrawTextViewAndGraphicalViewToBitmap(bmp);
        this.DrawHeaderAndTimelineViewToBitmap(bmp);
        bmp.Save(path);
 
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Yemo
Top achievements
Rank 1
Iron
answered on 22 Mar 2017, 09:43 AM

Ok thanks. Worked for me.

I guess you guys have your reasons for making the methods internal.

0
CHEE HANG
Top achievements
Rank 1
answered on 15 Jan 2018, 12:48 AM

hi how do we apply the class. i have this class in my source. But i couldn't see this export function when i enter the control name 

please see the screenshot[quote]Dimitar said:Hello Yemi,

Thank you for writing.

We have internal methods that can export the Gantt to an image, they are used for printing. Here is how you can use them to create an image:

class MyGantt : RadGanttView
{
    public void Export(string path)
    {
        GanttViewTraverser traverser = new GanttViewTraverser(this.GanttViewElement);
        traverser.TraverseAllItems = true;
        List<GanttViewDataItem> flatItemsCollection = new List<GanttViewDataItem>();
 
        while (traverser.MoveNext())
        {
            flatItemsCollection.Add(traverser.Current);
        }
        float height = flatItemsCollection.Count * this.ItemHeight + this.HeaderHeight;
        float width = (float)((this.GanttViewElement.GraphicalViewElement.TimelineBehavior.AdjustedTimelineEnd.AddDays(1) - this.GanttViewElement.GraphicalViewElement.TimelineBehavior.AdjustedTimelineStart).TotalSeconds /
          (float)this.GanttViewElement.GraphicalViewElement.OnePixelTime.TotalSeconds);
         
        Bitmap bmp = new Bitmap((int)width,(int)height);
        int columnsWidth = 0;
 
        foreach (GanttViewTextViewColumn col in this.Columns)
        {
            if (col.Visible)
            {
                columnsWidth += col.Width;
            }
        }
 
        this.drawArea = new RectangleF(0, 0, columnsWidth, 100);
 
        using (Graphics grp = Graphics.FromImage(bmp))
        {
            grp.FillRectangle( Brushes.White, 0, 0, bmp.Width, bmp.Height);
        }
 
        this.DrawTextViewAndGraphicalViewToBitmap(bmp);
        this.DrawHeaderAndTimelineViewToBitmap(bmp);
        bmp.Save(path);
 
    }
}


I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress

Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.

[/quote]

0
Dimitar
Telerik team
answered on 15 Jan 2018, 11:15 AM
Hi Chee,

Open the designer file and replace the default RadGantView with the custom one. The attached image shows how you can do that. 

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Omar
Top achievements
Rank 1
answered on 09 Feb 2019, 06:07 PM

Hi,

I am trying to use you code, but I can get it the function  radGanttView1.Export("path");

Am I missing something?

Many thanks,

Omar

0
Dimitar
Telerik team
answered on 11 Feb 2019, 01:41 PM
Hi Omar,

I am not sure why this is not working on your side. I would recommend opening a support ticket and attaching your code. This way we will be able to properly investigate this case. 

Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GanttView
Asked by
Yemo
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Yemo
Top achievements
Rank 1
Iron
CHEE HANG
Top achievements
Rank 1
Omar
Top achievements
Rank 1
Share this question
or