Page 1 of 1
Saving Themes
Posted: Wed Sep 15, 2010 12:59 pm
by 9641422
When I save the theme after changing the settings of chart, series using chart editor and then after loading the saved theme I am not getting what I saved.
Example: I change the color of the series and series pointers and save the theme. But when I load that saved theme the color changes to orange. Following is code what I have done.
To save theme :
Code: Select all
private void SaveCustomTheme()
{
chartTestPeriod.Export.Theme.SaveWithBase64 = false;
String strPath;
strPath = Application.StartupPath.ToString();
strPath += @"\Theme";
string strFile = strPath + "\\Theme.xml";
try
{
if (!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
chartTestPeriod.Export.Theme.Save(strFile);
}
catch (Exception ex)
{
}
}
To load theme :
Code: Select all
private void LoadCustomTheme()
{
String strPath;
strPath = Application.StartupPath.ToString();
strPath += @"\Theme";
string strFile = strPath + "\\Theme.xml";
try
{
if (Directory.Exists(strPath))
{
chartTestPeriod.Import.Theme.Load(strFile);
}
}
catch (Exception ex)
{
}
}
Thanks & Regards
Yatendra Kashyap
Re: Saving Themes
Posted: Wed Sep 15, 2010 3:43 pm
by 10050769
Hello Amol,
I could reproduce your problem and I have added it in bug report list with number [TF02015155]. We will try to fix it for next maintenance releases of TeeChart.Net
Thanks,
Re: Saving Themes
Posted: Thu Sep 16, 2010 10:55 am
by 10050769
Hello Amol,
I have informed you that this bug [
TF02015155] is not a bug, because the Series Color is not kept in the theme.xml file when SaveWithBase64=false. What is kept in the theme.xml file when SaveWithBase64=false is the Color Palette. So, the following code will work fine:
Code: Select all
private void InitializeChart()
{
tChart1.Chart.ColorPalette = new Color[] { Color.Red, Color.Green };
tChart1.Series.Add(typeof(Line)).FillSampleValues();
}
private void button1_Click(object sender, EventArgs e)
{
SaveCustomTheme();
}
private void button2_Click(object sender, EventArgs e)
{
LoadCustomTheme();
}
Thanks,
Re: Saving Themes
Posted: Tue Sep 21, 2010 7:50 am
by 9641422
Hello Sandra,
Thank you very much for your support.
I want to let you confirm what actually I am doing. In short we have two sets of array by which we are displaying the series. In one of the series we are able to make changes by dragging the pointers. There after those arrays also modified accordingly. We are saving the arrays in binary file and when we open that binary file in our project data is read from that binary file and then both series are redrawn with that data. Other information of the project is also saved in the same binary file. Hence we don’t want to save the data in the theme file and that’s why we are saving the theme with the base64 false.
When we use SaveWithBase64=true, everything is perfectly restored when we load theme, but we don’t want to save the data in the theme file. We want to save everything else that is saved in the theme file while base64 is true except data. While setting SaveWithBase64=false, we are able to manipulate the series, but the problem is that, still many things like series color, gridlines etc. are not restored when we load theme file .
Thanks in advance for your support.
Thanking and regards
Yatendra Kashyap
Re: Saving Themes
Posted: Wed Sep 22, 2010 1:16 pm
by 10050769
Hello Yatendra Kashyap,
Sorry for the delay. I suggest an other way to save themes of your chart, using a *.ten file with IncludeData=false. You can do something similar as next example I have made:
Code: Select all
public void InitializeChart()
{
tChart1.Series.Add(typeof(Bar));
tChart1.Series.Add(typeof(Line));
Random rnd = new Random();
for (int i = 0; i < 20; i++)
{
tChart1[0].Add(i, rnd.NextDouble());
tChart1[1].Add(i, rnd.NextDouble());
}
}
private void button1_Click(object sender, EventArgs e)
{
MemoryStream ms = new MemoryStream();
tChart1.Export.Template.IncludeData = false;
tChart1.Export.Template.Save(ms);
ms.Position = 0;
tChart2.Import.Template.Load(ms);
}
Could you please, tell us if previous code works as you want?
I hope will helps.
Thanks,
Re: Saving Themes
Posted: Thu Sep 23, 2010 6:57 am
by 9641422
Hello Sandra,
Thank you very much for your support.
The method you provided is fine to save the theme of the chart. But the problem is we want to save the theme in a separate file on the hard disk and whenever we want to load the theme we will use that file. Your code saves the theme in a memory stream object and then loads the theme back from the same object. The object of memory stream is vanished when we close the application.
I found that we can pass the file name in the "tChart1.Export.Template.Save" method and then it saves the theme in a fie on the disk. But when we do this with "IncludeData" property false then it do not saves the data(that is what we wanted to do) but when we load the theme from the file on the chart then it shows a blank chart but the theme is restored. I am filling the data in the series before loading the theme to the chart from the file but it shows just a blank chart, however it restores the theme. But without data it is of no use.
When I do it with “IncludeData" property true the it saves both the theme and data to the file on the disk. When we try to apply the theme on some other chart, it also clears the data initialized in the series and shows the data with which the theme is saved. That is, i apply theme on whichever chart I get the same data.
Also you mentioned about *.ten file, but did not tell how to use it. Any way I am saving the theme in Theme.ten file, but I think extension of file has nothing to do with it.
Please see following code...
//Saving the theme
Code: Select all
public void InitializeChart()
{
tChart1.Series.Add(typeof(Bar));
tChart1.Series.Add(typeof(Line));
Random rnd = new Random();
for (int i = 0; i < 20; i++)
{
tChart1[0].Add(i, rnd.NextDouble());
tChart1[1].Add(i, rnd.NextDouble());
}
}
private void SaveTheme()
{
tChart1.Export.Template.IncludeData = false;
tChart1.Export.Template.Save("Theme.ten");
}
//Loading the theme
Code: Select all
public void InitializeChart()
{
tChart2.Series.Add(typeof(Bar));
tChart2.Series.Add(typeof(Line));
Random rnd = new Random();
for (int i = 0; i < 20; i++)
{
tChart2[0].Add(i, rnd.NextDouble());
tChart2[1].Add(i, rnd.NextDouble());
}
}
private void SaveTheme()
{
tChart2.Import.Template.Load("Theme.ten");
}
But what I get on tchart2 is the theme which I saved in the file and no data is there.
Thanks in advance for your support.
Thanking and regards
Yatendra Kashyap
Re: Saving Themes
Posted: Fri Sep 24, 2010 9:42 am
by 10050769
Hello Amol,
I suggest you use export with template with export and import theme and you use XmlSource or TextSource component of TeeChart .Net for save data of Chart2. When theme has been uploaded, you can import data.You could find and example concretely in the Tutorial12: Exporting and Importing Charts, how you use xmlSource component.
Could you please tell us if you use XmlSource or TexSource your problem is solved? If it don't works fine for you please let us know.
Thanks,