Saving chart with itextsharp

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Saving chart with itextsharp

Post by Fulcrum » Wed May 22, 2013 10:16 am

When i try to sa ve a chart with itexrsharp the botton axis dont have all the labels

Image

I have tried the propertie width and heigth to resize the image and achieve that peoblem but now the label are very tiny

Image

Id apreciate any help

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving chart with itextsharp

Post by Sandra » Wed May 22, 2013 2:05 pm

Hello Fulcrum,

I have made a simple code that can help you to achieve as you want:

Code: Select all

          public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        Steema.TeeChart.Styles.Bar series1;
        private void InitializeChart()
        {
            tChart1.Walls.Back.Visible = false;
            series1 = new Bar(tChart1.Chart);
            tChart1.Legend.Visible = false; 
            series1.Add(0, 5000);
            series1.Add(1, 95000);
            series1.Add(2, 50000);
            series1.Add(3, 34000);
            series1.Add(4, 68000);
            tChart1.Axes.Bottom.Labels.Items.Clear();
            for (int i = 0; i < series1.Count; i++)
            {
                if (i == 0)
                {
                    tChart1.Axes.Bottom.Labels.Items.Add(series1.XValues[i], "Grava cemento");
                }
                else if (i == 1)
                {
                    tChart1.Axes.Bottom.Labels.Items.Add(series1.XValues[i], "Grava Suelo");
                }
                else if (i == 2)
                {
                    tChart1.Axes.Bottom.Labels.Items.Add(series1.XValues[i], "Zahorra");
                }
                else if (i == 3)
                {
                    tChart1.Axes.Bottom.Labels.Items.Add(series1.XValues[i], "Betunes");

                }
                else if (i == 4)
                {
                    tChart1.Axes.Bottom.Labels.Items.Add(series1.XValues[i], "Mezclas Bifuminosas");
                }
            }
            tChart1.Axes.Bottom.Labels.Angle = 45;
            tChart1.Export.Image.PDF.Save(@"C:\tmp\tchart1.pdf"); 
        }

   
        private void button1_Click(object sender, EventArgs e)
        {
            tChart1.Export.Image.PDF.Save(@"C:\tmp\tchart1.pdf"); 
        }
Could you tell us if previous code works in your end?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Re: Saving chart with itextsharp

Post by Fulcrum » Thu May 23, 2013 8:28 am

Thank for you reoply Sandra but its not working.

in my program i export first the chart to a jpeg:

Code: Select all

 WebChartTripleBarras2.Chart.Export.Image.JPEG.Save("C:\ImagenInformeTripleBarras2.jpeg")
but didnt show all the axis, so i use:

Code: Select all

JpegBarras2.Quality = 100
JpegBarras2.Width = 900 
JpegBarras2.Height = 700
to resize the image.

I hope you could help me

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving chart with itextsharp

Post by Sandra » Thu May 23, 2013 4:03 pm

Hello Fulcrum,

Thanks for information. We would be very grateful if you can arrange for us a simple code, where we can reproduce the problem exactly, because here If I use custom labels, the problem disappears.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Re: Saving chart with itextsharp

Post by Fulcrum » Fri May 24, 2013 7:47 am

Code: Select all

Dim ch3 As Steema.TeeChart.Chart = WebChartTripleBarras3.Chart
        ch3.Series.RemoveAllSeries()
        ch3.Series.Add(New Steema.TeeChart.Styles.Bar())
        ch3.Series(0).Add(72049.789999999994, "Desmonte Total")
        ch3.Series(0).Add(23371.139999999999, "Volumen de Vertedero")
        ch3.Series(0).Add(71177.119999999995, "Rellenos con Mat. Excavacion")
        ch3.Series(0).Add(91177.119999999995, "Rellenos con Mat. Prestamo")
        ch3.Series(0).Add(53371.139999999999, "Seleccinado de Excavacion")
        ch3.Series(0).Add(1177.1199999999949, "Selecciondo de Prestamo")
        ch3.Series(0).Add(0, "Cemento Suelo Estabilizado")
        ch3.Series(0).Add(11177.119999999995, "Resto de unidades")
        ch3.Series(0).Marks.Visible = False
        ch3.Legend.Shadow.Visible = True
        ch3.Legend.Visible = False
        ch3.Series(0).ShowInLegend = False
        ch3.Walls.Back.Gradient.Visible = False
        ch3.Walls.Back.Color = Color.White
        ch3.Panel.Gradient.Visible = False
        ch3.Panel.Color = Color.White
        ch3.Series(0).Color = Color.CornflowerBlue
        ch3.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None
        ch3.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None
        ch3.Axes.Bottom.Labels.Angle = 50
        Dim JpegBarras3 As Steema.TeeChart.Export.JPEGFormat = ch3.Export.Image.JPEG
        JpegBarras3.Quality = 100
        JpegBarras3.Width = 2000 'm_PictureBox.Width
        JpegBarras3.Height = 900 'm_PictureBox.Height
        WebChartTripleBarras3.Chart.Export.Image.JPEG.Save("C:\ImagenInformeTripleBarras3.jpeg")

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving chart with itextsharp

Post by Sandra » Fri May 24, 2013 1:00 pm

Hello Fulcrum,

I have made a simple code, where I am using with custom labels and your problems is solved:

Code: Select all

        Steema.TeeChart.Styles.Bar series1; 
        string [] labelstext; 
        private void InitializeChart()
        {
            WebChart1.Chart.Aspect.View3D = false;
            series1 = new Bar(WebChart1.Chart);
           labelstext = new string[]{"Desmonte Total","Volumen de Vertedero","Rellenos con Mat. Excavacion","Rellenos con Mat. Prestamo",
               "Seleccinado de Excavacion","Selecciondo de Prestamo","Cemento Suelo Estabilizado","Resto de unidades"}; 
            series1.Add(72049.789999999994, "Desmonte Total");
            series1.Add(23371.139999999999, "Volumen de Vertedero");
            series1.Add(71177.119999999995, "Rellenos con Mat. Excavacion");
            series1.Add(91177.119999999995, "Rellenos con Mat. Prestamo");
            series1.Add(53371.139999999999, "Seleccinado de Excavacion");
            series1.Add(1177.1199999999949, "Selecciondo de Prestamo");
            series1.Add(0, "Cemento Suelo Estabilizado");
            series1.Add(11177.119999999995, "Resto de unidades");
            series1.Marks.Visible = false;
            WebChart1.Chart.Legend.Shadow.Visible = true;
            WebChart1.Chart.Legend.Visible = false;
            //CUSTOM LABELS
            AddCustomLabels(series1,labelstext); 
           
            WebChart1.Chart.Axes.Bottom.Labels.Angle = 50;
            WebChart1.Chart.Export.Image.JPEG.Quality = 100;
            WebChart1.Chart.Export.Image.JPEG.Width = 2000;
            WebChart1.Chart.Export.Image.JPEG.Height = 900;
            WebChart1.Chart.Export.Image.JPEG.Save(@"C:\ImagenInformeTripleBarras3.jpeg");
        }


        protected void AddCustomLabels(Series s, string[] arraylabels)
        {
            WebChart1.Chart.Axes.Bottom.Labels.Items.Clear();
            for (int i = 0; i < series1.Count; i++)
            {
                WebChart1.Chart.Axes.Bottom.Labels.Items.Add(s.XValues[i], arraylabels[i]); 
            }

        }
Could you please, check my previous code?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Re: Saving chart with itextsharp

Post by Fulcrum » Mon May 27, 2013 11:59 am

i have converted the code to vb.net and visual studio dont recognize series as a class

Code: Select all

Protected Sub AddCustomLabels(s As Series, arraylabels As String())
I woul like to know another thing, is posible on the y axis mark the label of certain values like every 50.000 for example changing the color or making more extensive the line

Thank you for helping me

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving chart with itextsharp

Post by Sandra » Mon May 27, 2013 3:44 pm

Hello Fulcrum,

I have converted my c# code to vb code and it works in correct way:

Code: Select all

 Private series1 As Steema.TeeChart.Styles.Bar
    Private labelstext As String()
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        InitializeChart()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Private Sub InitializeChart()
       WebChart1.Chart.Aspect.View3D = False
        series1 = New Steema.TeeChart.Styles.Bar(TChart2.Chart)
        labelstext = New String() {"Desmonte Total", "Volumen de Vertedero", "Rellenos con Mat. Excavacion", "Rellenos con Mat. Prestamo", "Seleccinado de Excavacion", "Selecciondo de Prestamo", _
            "Cemento Suelo Estabilizado", "Resto de unidades"}
        series1.Add(72049.79, "Desmonte Total")
        series1.Add(23371.14, "Volumen de Vertedero")
        series1.Add(71177.12, "Rellenos con Mat. Excavacion")
        series1.Add(91177.12, "Rellenos con Mat. Prestamo")
        series1.Add(53371.14, "Seleccinado de Excavacion")
        series1.Add(1177.11999999999, "Selecciondo de Prestamo")
        series1.Add(0, "Cemento Suelo Estabilizado")
        series1.Add(11177.12, "Resto de unidades")
        series1.Marks.Visible = False
       WebChart1.Chart.Legend.Shadow.Visible = True
       WebChart1.Chart.Legend.Visible = False
        'CUSTOM LABELS
        AddCustomLabels(series1, labelstext)

        WebChart1.Chart.Axes.Bottom.Labels.Angle = 50
       WebChart1.Chart.Export.Image.JPEG.Quality = 100
       WebChart1.Chart.Export.Image.JPEG.Width = 2000
       WebChart1.Chart.Export.Image.JPEG.Height = 900
       WebChart1.Chart.Export.Image.JPEG.Save("C:\ImagenInformeTripleBarras3.jpeg")
    End Sub


    Protected Sub AddCustomLabels(s As Steema.TeeChart.Styles.Series, arraylabels As String())
       WebChart1.Chart.Axes.Bottom.Labels.Items.Clear()
        For i As Integer = 0 To series1.Count - 1
           WebChart1.Chart.Axes.Bottom.Labels.Items.Add(s.XValues(i), arraylabels(i))
        Next

    End Sub
Could you tell us if previous code works in your end?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Re: Saving chart with itextsharp

Post by Fulcrum » Tue May 28, 2013 9:34 am

I have tried your solution but now the chart in the webpage dont have all the labels in the axis

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving chart with itextsharp

Post by Sandra » Tue May 28, 2013 2:10 pm

Hello Fulcrum,

Using my previous code with last version of TeeChart 2012:

Code: Select all

Private series1 As Steema.TeeChart.Styles.Bar
    Private labelstext As String()
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        InitializeChart()
        ' Add any initialization after the InitializeComponent() call.
    End Sub
    Private Sub InitializeChart()
       WebChart1.Chart.Aspect.View3D = False
        series1 = New Steema.TeeChart.Styles.Bar(TChart2.Chart)
        labelstext = New String() {"Desmonte Total", "Volumen de Vertedero", "Rellenos con Mat. Excavacion", "Rellenos con Mat. Prestamo", "Seleccinado de Excavacion", "Selecciondo de Prestamo", _
            "Cemento Suelo Estabilizado", "Resto de unidades"}
        series1.Add(72049.79, "Desmonte Total")
        series1.Add(23371.14, "Volumen de Vertedero")
        series1.Add(71177.12, "Rellenos con Mat. Excavacion")
        series1.Add(91177.12, "Rellenos con Mat. Prestamo")
        series1.Add(53371.14, "Seleccinado de Excavacion")
        series1.Add(1177.11999999999, "Selecciondo de Prestamo")
        series1.Add(0, "Cemento Suelo Estabilizado")
        series1.Add(11177.12, "Resto de unidades")
        series1.Marks.Visible = False
        WebChart1.Chart.Legend.Shadow.Visible = True
        WebChart1.Chart.Legend.Visible = False
        'CUSTOM LABELS
        AddCustomLabels(series1, labelstext)

        WebChart1.Chart.Axes.Bottom.Labels.Angle = 50
       WebChart1.Chart.Export.Image.JPEG.Quality = 100
       WebChart1.Chart.Export.Image.JPEG.Width = 2000
       WebChart1.Chart.Export.Image.JPEG.Height = 900
       WebChart1.Chart.Export.Image.JPEG.Save("C:\ImagenInformeTripleBarras3.jpeg")
    End Sub

    Protected Sub AddCustomLabels(s As Steema.TeeChart.Styles.Series, arraylabels As String())
       WebChart1.Chart.Axes.Bottom.Labels.Items.Clear()
        For i As Integer = 0 To series1.Count - 1
           WebChart1.Chart.Axes.Bottom.Labels.Items.Add(s.XValues(i), arraylabels(i))
        Next

    End Sub
I have achieved next result in the browser:
ChartinBrowser.jpg
ChartinBrowser.jpg (86.31 KiB) Viewed 15684 times
I have gotten next image using your indications to export the chart:
ImagenInformeTripleBarras3.jpeg
ImagenInformeTripleBarras3.jpeg (333.64 KiB) Viewed 15682 times
I consider the results are correct. For this reason,I would be very grateful if you can indicate us, if the problem appears in my attached images. If it doesn't appear, please try to modify the code, so we can reproduce your problem here. On the other hand, could you please tell us which version of TeeChart are you using in this moment?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Re: Saving chart with itextsharp

Post by Fulcrum » Wed May 29, 2013 12:17 pm

yes the problema is in the second chart and in my intructions for saving the chart.
In my web the chart dont have all the axis
Image

so to make then to appear I have to make the image larger

Now I havee notice something in your code that i didnt do when I tried it

Code: Select all

series1 = New Steema.TeeChart.Styles.Bar(TChart2.Chart)
when you define series1 you use TChart2, how do you define it. I defined it like the chart I was using and that could be my mistake.
Do I have to define a second chart?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving chart with itextsharp

Post by Sandra » Thu May 30, 2013 9:27 am

Hello Fulcrum,

I have attached my project where your problem doesn't appear using latest versions of TeeChartFor.Net (4.1.2012.01312). For this reason, we would be very grateful if you can check my attached project and inform us of results you get.
On the other hand, could you confirm us which version are you using?
WebSite7.zip
(5.98 KiB) Downloaded 471 times
Now I havee notice something in your code that i didnt do when I tried it

CODE: SELECT ALL
series1 = New Steema.TeeChart.Styles.Bar(TChart2.Chart)
when you define series1 you use TChart2, how do you define it. I defined it like the chart I was using and that could be my mistake.
Do I have to define a second chart?
Sorry, I have forgotten to remove this line of code, isn't necessary.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Re: Saving chart with itextsharp

Post by Fulcrum » Thu May 30, 2013 12:17 pm

Hello Sandra and thank you, your projects Works fine and I have fixed the problema but when i tried in this one dont seem it solves anything.

Code: Select all

labelstext1 = New String() {"Hormigon", "Acero Estructural", "Acero con Arma. Pasivas", "Acero en Pretensados"}
        Dim ch1 As Steema.TeeChart.Chart = WebChartTripleBarras1.Chart
        ch1.Series.RemoveAllSeries()
        ch1.Series.Add(New Steema.TeeChart.Styles.Bar())
        Dim SeriesBar1 As New Steema.TeeChart.Styles.Bar()
        SeriesBar1.Add(72049.789999999994, "Hormigon")
        SeriesBar1.Add(23371.139999999999, "Acero Estructural")
        SeriesBar1.Add(71177.119999999995, "Acero con Arma. Pasivas")
        SeriesBar1.Add(91177.119999999995, "Acero en Pretensados")
        SeriesBar1.Marks.Visible = False
        'ch1.Legend.Shadow.Visible = True
        ch1.Legend.Visible = False
        ch1.Series(0).ShowInLegend = False
        'ch1.Series(0).Color = Color.CornflowerBlue
        ch1.Walls.Back.Gradient.Visible = False
        ch1.Walls.Back.Color = Color.White
        ch1.Panel.Gradient.Visible = False
        ch1.Panel.Color = Color.White
        ch1.Axes.Bottom.Labels.Angle = 30
        SeriesBar1.Color = Color.Blue
        SeriesBar1.Gradient.StartColor = Color.RoyalBlue
        SeriesBar1.Gradient.MiddleColor = Color.DodgerBlue
        SeriesBar1.Gradient.EndColor = Color.DeepSkyBlue
        SeriesBar1.Gradient.UseMiddle = True
        SeriesBar1.Gradient.Visible = True
        SeriesBar1.BarStyle = Steema.TeeChart.Styles.BarStyles.RectGradient
        AddCustomLabelsBar1(SeriesBar1, labelstext1)
        ch1.Series.Add(SeriesBar1)

        'ch1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None
        Dim JpegBarras1 As Steema.TeeChart.Export.JPEGFormat = ch1.Export.Image.JPEG
        JpegBarras1.Quality = 100
        JpegBarras1.Width = 900 'm_PictureBox.Width
        JpegBarras1.Height = 700 'm_PictureBox.Height
        WebChartTripleBarras1.Chart.Export.Image.JPEG.Save("C:\ImagenInformeTripleBarras1Final.jpeg")
Could it be I miss something?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Saving chart with itextsharp

Post by Sandra » Thu May 30, 2013 3:02 pm

Hello Fulcrum,

I have modified a little your code and using it but my AddCustomLabels method, your code works in correct way:

Code: Select all

       Private series1 As Steema.TeeChart.Styles.Bar
    Private labelstext As String()
    Private ch1 As Steema.TeeChart.Chart
    Private Sub InitializeChart()
        ch1 = WebChart1.Chart()
        labelstext = New String() {"Hormigon", "Acero Estructural", "Acero con Arma. Pasivas", "Acero en Pretensados"}
        Dim SeriesBar1 As New Steema.TeeChart.Styles.Bar(ch1)
        SeriesBar1.Add(72049.79, "Hormigon")
        SeriesBar1.Add(23371.14, "Acero Estructural")
        SeriesBar1.Add(71177.12, "Acero con Arma. Pasivas")
        SeriesBar1.Add(91177.12, "Acero en Pretensados")
        SeriesBar1.Marks.Visible = False
        ch1.Legend.Visible = False
        ch1.Series(0).ShowInLegend = False
        ch1.Walls.Back.Gradient.Visible = False
        ch1.Walls.Back.Color = Color.White
        ch1.Panel.Gradient.Visible = False
        ch1.Panel.Color = Color.White
        ch1.Axes.Bottom.Labels.Angle = 30
        SeriesBar1.Color = Color.Blue
        SeriesBar1.Gradient.StartColor = Color.RoyalBlue
        SeriesBar1.Gradient.MiddleColor = Color.DodgerBlue
        SeriesBar1.Gradient.EndColor = Color.DeepSkyBlue
        SeriesBar1.Gradient.UseMiddle = True
        SeriesBar1.Gradient.Visible = True
        SeriesBar1.BarStyle = Steema.TeeChart.Styles.BarStyles.RectGradient
        AddCustomLabels(SeriesBar1, labelstext)

        ch1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None
        Dim JpegBarras1 As Steema.TeeChart.Export.JPEGFormat = ch1.Export.Image.JPEG
        JpegBarras1.Quality = 100
        JpegBarras1.Width = 900 'm_PictureBox.Width
        JpegBarras1.Height = 700 'm_PictureBox.Height
        WebChart1.Chart.Export.Image.JPEG.Save("C:\ImagenInformeTripleBarras1Final.jpeg")
    End Sub

    Protected Sub AddCustomLabels(ByVal s As Steema.TeeChart.Styles.Series, ByVal arraylabels As String())
        ch1.Chart.Axes.Bottom.Labels.Items.Clear()
        For i As Integer = 0 To s.Count - 1
            ch1.Chart.Axes.Bottom.Labels.Items.Add(s.XValues(i), arraylabels(i))
        Next
    End Sub
I have made the test in VS2008 and latest version of TeeChartFor.Net. Do you use last version of TeeChartFor.Net?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fulcrum
Newbie
Newbie
Posts: 35
Joined: Fri Dec 21, 2012 12:00 am

Re: Saving chart with itextsharp

Post by Fulcrum » Mon Jun 03, 2013 10:29 am

Thank you for everything Sandra, the problema is finally solved

Post Reply