Page 1 of 1

Teechart .NET 4.2024.11.14 - Import/Export from/to .ten format doesn't work as expected

Posted: Fri Nov 22, 2024 8:52 am
by 15698365
Teechart .NET Pro - 4.2024.11.14

We are exporting our chart with data to .ten format using .NET version of Teechart. Later when we import the .ten file back to chart and save it as an image, the series data is missing. But saving the image directly works fine and renders well. I've replicated this issue in a sample .NET framework 4.8 console application and here's the code for the same. Also find attachments , one for image which is directly exported to PNG and the other which is imported from ten and then saved to image. Am I missing something?

Code: Select all

using Steema.TeeChart;
using Steema.TeeChart.Styles;
using System;
using System.Drawing;

class Program
{
    static void Main(string[] args)
    {
        Chart chart = new Chart();

        chart.Header.Text = "Sample TeeChart";
        chart.Header.Font.Size = 16;
        chart.Header.Font.Bold = true;

        Line series = new Line(chart.Chart);
        series.Title = "Sample Data";
        series.Color = Color.Blue;
        series.LinePen.Width = 2;

        for (int i = 0; i < 100; i++)
        {
            double x = i * 0.1;
            double y = Math.Sin(x) * Math.Exp(-x * 0.1);
            series.Add(x, y);
        }

        chart.Axes.Bottom.Title.Text = "X Axis";
        chart.Axes.Bottom.Title.Font.Size = 12;
        chart.Axes.Left.Title.Text = "Y Axis";
        chart.Axes.Left.Title.Font.Size = 12;

        chart.Panel.Brush.Color = Color.White;
        chart.Walls.Back.Pen.Visible = true;
        chart.Walls.Back.Pen.Width = 1;
        chart.Walls.Back.Pen.Color = Color.LightGray;

        chart.Width = 600;
        chart.Height = 400;


        string fileName = "teechart.ten";
        chart.Export.Template.IncludeData = true;
        chart.Export.Template.Save(fileName);

        Chart chart1 = new Chart();
        chart1.Import.Template.Load(fileName);
        chart1.Export.Image.PNG.Save("teechart.png");


        Console.WriteLine($"Chart saved as {fileName}");
    }
}

Re: Teechart .NET 4.2024.11.14 - Import/Export from/to .ten format doesn't work as expected

Posted: Mon Nov 25, 2024 9:55 am
by edu
Hello:

From a console application, please use the class TChart to access Export functionality. While the class 'Chart' does the job with UI Frameworks like Winforms, it is limited when it comes to console apps.

Here's how the code would look like, following the code you provided, instead of "Chart chart1 = ...".

Code: Select all

            //suggested code
            TChart chart2 = new TChart();
            chart2.Import.Template.Load(fileName);
            chart2.Export.Image.PNG.Save("Chart2.png");
If there's anything else I can help you with, please let me know!
Regards,
Edu