From Clomosy Docs

(Created page with "The TClChart component is the basic building block for charts. You can use this component to add a graphic to your application on Clomosy.<br> AddNewChart(TComponent, xName, xTitle) : TClChart <span style="color:blue"> TComponent</span> : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in. <span style="color:blue"> xName</span> : The name of the defined chart should be written....")
 
No edit summary
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The TClChart component is the basic building block for charts. You can use this component to add a graphic to your application on Clomosy.<br>
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
AddNewChart(TComponent, xName, xTitle) : TClChart
function AddNewChart(AComponent: TCLComponent; xName, , xTitle: string): TclChart;
</div>


<span style="color:blue"> TComponent</span> : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in.
<span style="color:blue"><b>AComponent</b></span> : Specifies the parent of the object to be defined.<br>


<span style="color:blue"> xName</span> : The name of the defined chart should be written.
<span style="color:blue"><b>xName</b></span> : The name of the defined chart should be written.<br>


<span style="color:blue"> xTitle</span> : You can add a title.
<span style="color:blue"><b>xTitle</b></span> : You can add a title.<br>


Let's create a label.<br>
This component, used to create graphics and drawings, can be used on a form or within another container. The TclChart component supports the creation of various data visualizations. These chart types include line charts, bar charts, pie charts, and area charts.<br>


1. Create a new project.<br>
<div class="table-responsive">
 
{| class="wikitable" style="border: 2px solid #c3d7e0"
2. You need to define TClChart on the form. To do this, you should add under the ''var'' parameter on the ide as follows. It is the name of your variable you typed at the beginning. You should define this as you want and add it as TClChart.<br>
! style="background-color: #c3d7e0"| Feature  !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition
'''var'''
|-
  testChart : TClChart;  
|TClChart || Chart1 : TClChart; || A variable belonging to the TClChart class is created.
 
|-
3. Add the TClChart to the form. For this, you must add the begin end block and add it inside the form after the form is defined. By saying MyForm.AddNewChart, we actually add to the form we have defined. Here, you need to add your form definition as whatever you wrote it.<br>
|AddNewChart || Chart1 = Form1.AddNewChart(Form1,'Chart1','Clomosy Inc'); || A new TClChart is added to the form.
 
|-
testChart := MyForm.'''AddNewChart'''(MyForm,'testChart','Clomosy Inc');
|Width || Chart1.Width = 150; ||Allows adjusting the width of the chart.
 
|-
4. If you do not want to define it in the form, you can add it in another component (such as Layout, Panel). Of course, before that, that component must be defined.
|Height || Chart1.Height = 50; ||Allows adjusting the height of the chart.
<span style="color:blue">testLayout</span> := MyForm.AddNewLayout(MyForm,'testLayout');
|-
testChart := MyForm.AddNewChart(<span style="color:blue">testLayout</span>,'testChart','Clomosy Inc');
|Align || Chart1.Align = alTop; ||With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the [[Object_Properties#Align | page]] to learn about these features.
 
|-
 
|Margins || Chart1.Margins.Left = 50; // Right, Top, Bottom ||With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.<br>[[File:TclChartMargins.png|frameless|200px]]<br><br>
5. We gave the variable name while defining the TclChart in var. Now when you add this in begin end you should use this variable name in all definitions. Your code will throw an error when you write these variable names incorrectly.
|-
 
|clLoadDataFromJSONStr<br>clLoadDataFromDataset || Chart1.clLoadDataFromJSONStr(simpleJSONStr); //simpleJSONStr: String;<br> Chart1.clLoadDataFromDataSet(Qry); // Qry(TclDataSet): TclSQLiteQuery || There are 2 different methods to add data to the TClChart component. With the json structure, data can be added or the data can be added by taking the data over the data set. Examples of these are given at the bottom of the page. Their identification procedures are as follows:
6. Now let's design our TclChart component. Let's set the width and height first. For this, you must make the following definitions.
|-
 
|XAxisText || Chart1.XAxisText = 'DeviceType'; || The x-axis area given for the values ​​to be compared
  testChart.Height := 50;
|-
testChart.Width := 150;
|ChartItemsValue ||Chart1.ChartItemsValue = 'Percent'; || The values ​​of the items entered on the X axis come and the graph is formed over these values.
 
|-
7. With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the [https://www.docs.clomosy.com/index.php/Object_Properties#Align page] to learn about these features. We're going to call it the top part here. So we have to write "AlTop".
|ChartItemText ||Chart1.ChartItemText = 'Device Sales'; || TIt is the title of graphic elements.
testChart.Align := alTop;
|-
 
|ChartTitle ||Chart1.ChartTitle = 'Samsoong Inc'; || The title of the chart.  
8. With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
|-
 
|Charttype ||Chart1.Charttype = clCBar; ||The ChartType parameter is used to change the graphic display. There are 4 graphic views available. Graph view properties definitions:<br>  
testChart.Margins.Left:= 50;
* <b>clCLine</b> : Line view.
testChart.Margins.Right:= 50;
* <b>clCBar</b> : It's a bar view.
testChart.Margins.Top:= 50;
* <b>clCPie</b> : It's a pie view.
testChart.Margins.Bottom:= 10;
* <b>clCSizedPie</b> : It is a sized pie view. <br>
 
<gallery widths="200px" heights="200px" mode="packed">
[[File:TclChartMargins.png|frameless|400px]]<br><br>
 
9. There are 2 different methods to add data to the TClChart component. With the json structure, data can be added or the data can be added by taking the data over the data set. Examples of these are given at the bottom of the page. Their identification procedures are as follows:<br>
procedure '''clLoadDataFromJSONStr'''(JsonStr:String);
procedure '''clLoadDataFromDataset'''(SourceDS:TDataSet);
 
10. It has TClChart features. These are the chart title on the chart, the x-axis area given for the values ​​to be compared, the chart item title, and the chart item values. Definitions:<br>
<span style="color:blue">'''XAxisText'''</span>      : String;
: The x-axis area given for the values ​​to be compared
'''Use Of:'''<br>
testChart.XAxisText := 'DeviceType';
 
<span style="color:blue">'''ChartItemsValue'''</span> : String;
: The values ​​of the items entered on the X axis come and the graph is formed over these values.
'''Use Of:'''<br>
testChart.ChartItemsValue := 'Percent';
 
<span style="color:blue">'''ChartItemText'''</span>  : String; 
: It is the title of graphic elements.
'''Use Of:'''<br>
testChart.ChartItemText := 'Device Sales';
 
<span style="color:blue">'''ChartTitle'''</span>      : String;
: The title of the chart.
'''Use Of:'''<br>
testChart.ChartTitle := 'Samsoong Inc';
 
11. Now let's move on to the chart views. There are 4 graphic views available. The "TChartType" parameter is used to change the graphic display. Graph view properties definitions:<br>
* '''clCLine''' : Line view.
* '''clCBar''' : It's a bar view.
* '''clCPie''' : It's a pie view.
* '''clCSizedPie''' : It is a sized pie view.
 
'''Use of:'''
testChart.Charttype := clCBar;
 
You can see their looks below.
<gallery widths="250px" heights="450px" mode="packed">
File: ChartClCLine.png | ''clCLine''
File: ChartClCLine.png | ''clCLine''
File: ChartClCBar.png | ''clCBar''
File: ChartClCBar.png | ''clCBar''
Line 85: Line 48:
File: ChartClCSizedPie.png | ''clCSizedPie''
File: ChartClCSizedPie.png | ''clCSizedPie''
</gallery><br>
</gallery><br>
|-
|SetAutoXRange - SetAutoYRange || Chart1.SetAutoXRange(4);<br> Chart1.SetAutoYRange(3);|| These procedures are used to adjust the automatic ranges of the X and Y axes in a graph. They allow you to enable or disable specific behaviors for determining the axis ranges based on the data displayed on the graph. The parameter values can be set as follows:<br>
* <b>0: arDisabled</b>: Automatic range is disabled. This means that axis ranges are set manually and will not be adjusted automatically.
* <b>1: arEnabled</b>: Automatic range is enabled. In this case, the data range on the X or Y axis is automatically calculated and adjusted.
* <b>2: arEnabledZeroBased</b>: Automatic range is enabled and the axis range is started from zero. This ensures that the axis starts at zero, and the remaining range is calculated automatically.
* <b>3: arCommon</b>: A common automatic range is used. This option typically allows for the same range to be used for multiple datasets.
* <b>4: arCommonZeroBased</b>: Common range is started from zero. The same zero-based range is used for all datasets.
|-
|SetInteractionPanning ||Chart1.SetInteractionPanning(True); || It is used to control panning interaction in graphical components. Panning allows the image within a graph or visualization area to be moved horizontally or vertically. This feature is particularly useful in large datasets, as it enables users to view different parts of the graph effectively.
|-
|SetInteractionScaleMode ||Chart1.SetInteractionScaleMode(2); || It is used to control the scaling interaction in a graphical component. This feature determines how users can perform scaling (zoom) interactions within the graph or visualization area. The parameter values can be set as follows:<br>
*<b>0: smNone</b>: Scaling interaction is disabled. Users cannot zoom in or out on the graph.


12. When you want to specify the colors of the values ​​on the chart, you can color them by typing "color":"clOrange" as in the example.
*<b>1: smHorizontal</b>: Only horizontal scaling is enabled. Users can zoom in or out on the graph horizontally.


simpleJSONStr := '[{ "DeviceType": "Notebook","Percent": 50,<span style="color:orange">"color":"clOrange"</span>}]';
*<b>2: smVertical</b>: Only vertical scaling is enabled. Users can zoom in or out on the graph vertically.
|-
|XValuesAngle ||Chart1.XValuesAngle = 20.0; || It specifies the angle of the value labels on the X axis. This angle is typically adjusted in degrees.
|-
|Legend ||Chart1.Legend.Visible = True; || It is a property that determines the visibility of the legend on the chart. When set to False, the legend becomes invisible on the chart.
|-
|Series ||Chart1.Series.Clear; || It allows you to reset the chart by removing the existing data series on the chart.
|}
</div>
 
<div class="alert alert-ligth border border-3 border-warning rounded-5 p-4 shadow-sm" role="alert">
When you want to specify the colors of the values ​​on the chart, you can color them by typing "color":"clOrange" as in the example.
<pre>
simpleJSONStr = '[{ "DeviceType": "Notebook","Percent": 50,"color":"clOrange"}]'; //simpleJSONStr: String;
</pre>


Available colors:<br>
Available colors:<br>
Line 104: Line 93:
* clPeru
* clPeru
* clOrange
* clOrange
</div>


14. To tell you the truth, you have created a simple application that does nothing yet. Let's save and start using our project. You can save in one of two ways:<br>
Click the save icon (the button in the upper right corner) or press Ctrl + S to save the project and see what you've done on the platforms now.


Now let's make an example with both the json structure and the dataset.
<h2>Example : Usage with JSON Data</h2><br>
==== JSON Data Example ====
<pre>
-------------------
  var
 
   MyForm:TclForm;
  '''var'''
   MyForm:TFrmClomosyBasisForm;
   testChart : TClChart;
   testChart : TClChart;
   simpleJSONStr : String;<br>
   simpleJSONStr : String;
  '''begin'''
   
   MyForm := TFrmClomosyBasisForm.Create(Self);
{
   testChart := MyForm.AddNewChart(MyForm,'testChart','Samsoong');
   MyForm = TclForm.Create(Self);
   simpleJSONStr := '[{ "DeviceType": "Notebook","Percent": 50,"color":"clOrange"},{"DeviceType" : "Tablet","Percent": 35,"color":"clPink"},{"DeviceType" : "Phone","Percent": 73,"color":"clTomato"}]';<br>
   testChart = MyForm.AddNewChart(MyForm,'testChart','Samsoong');
   testChart.Charttype := clCBar;
   simpleJSONStr = '[{ "DeviceType": "Notebook","Percent": 50,"color":"clOrange"},{"DeviceType" : "Tablet","Percent": 35,"color":"clPink"},{"DeviceType" : "Phone","Percent": 73,"color":"clTomato"}]';
   testChart.XAxisText := 'DeviceType';
   testChart.ChartItemText := 'Device Sales';
   testChart.Charttype = clCBar;
   testChart.ChartItemsValue := 'Percent';
   testChart.XAxisText = 'DeviceType';
   testChart.ChartTitle := 'Samsoong Inc';
   testChart.ChartItemText = 'Device Sales';
   testChart.'''clLoadDataFromJSONStr'''(simpleJSONStr);
   testChart.ChartItemsValue = 'Percent';
   MyForm.Run;<br>
   testChart.ChartTitle = 'Samsoong Inc';
'''end;'''
   testChart.clLoadDataFromJSONStr(simpleJSONStr);
   MyForm.Run;
}
</pre>


<b>Output:</b><br>
[[File:ChartJSOnDataExample.png|350px|frameless]]<br>




'''Output:'''<br>
<h2>Example: Usage with Data Set</h2><br>
[[File:ChartJSOnDataExample.png|350px|frameless]]
<pre>
 
  var
==== Data Set Example ====
    MyForm : TclForm;
-------------------
    Chart1 : TClChart;
 
  void SqLiteInsertData;
  {
    try
      Clomosy.DBSQLiteQuery.Sql.Text = '
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (1, ''Vista'',''Microsoft Windows'',''tablet'', 200);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''XP'',''Microsoft Windows'',''tablet'', 500);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Microsoft Windows'',''computer'', 104);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Public Beta'',''MacOS'',''computer'', 400);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (2, ''Tiger'',''MacOS'',''tablet'', 350);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Leopard'',''MacOS'',''computer'', 125);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (3, ''Lollipop'',''Android'',''mobile'', 325);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Android'',''tablet'', 123);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (4, ''Gnome'',''Pardus'',''computer'', 300);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Raspberry'',''Pardus'',''computer'', 175);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (5, ''Tiger'',''MacOS'',''mobile'', 10);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''MacOS'',''ipad'', 104);';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
     
      ShowMessage('Adding data to the table was successful!');
    except
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
 
  void SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
  {
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProductSales.db3', '');
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="OperatingSystem";';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
     
      // Check the results
      TableExists = not Clomosy.DBSQLiteQuery.Eof;
     
      // Create the table if it does not exist
      if not (TableExists)
      {
        Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE OperatingSystem (
                                        id INTEGER NOT NULL,
                                        model TEXT NOT NULL,
                                        operating_system TEXT NOT NULL,
                                        device_type TEXT NOT NULL,
                                        sales_figure INTEGER NOT NULL
                                          )';
        Clomosy.DBSQLiteQuery.OpenOrExecute;
       
        ShowMessage('Table successfully added to the database!');
        SqLiteInsertData;
      } else
      {
        ShowMessage('The Products table already exists.');
      }


'''Var''' 
    except
  MyForm:TFrmClomosyBasisForm;
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
  testListview : TClProListView;
    }
  testDesignerPanel : TClProListViewDesignerPanel;
   }
  MAIN_TEXT,myLabel : TClProLabel;
    
  ImgUrl : TClProImage;
  void AddDataToChart;
  searchEdt : TClProSearchEdit;
  Var
   testButton : TclButton;
     Qry : TClSQLiteQuery;
   testChart : TClChart;
  {
  simpleJSONStr : String;
  '''procedure''' SetupSqlConnection;
  '''begin'''
    Clomosy.DBSQLServerConnect('SQL Server','server_name','user_name','user_password','database_name',port);
'''end;'''<br>
'''procedure''' AddDataToListview;
'''Var'''
     foodListQuery : TClSqlQuery;
  '''begin'''
    foodListQuery := TClSqlQuery.Create(nil);
     try
     try
       foodListQuery.Connection := Clomosy.DBSQLServerConnection;
       Qry = Clomosy.DBSQLiteQueryWith('SELECT SUM(sales_figure) AS SALES, case when device_type ='+QuotedStr('tablet')+'  
      foodListQuery.SQL.Text := 'SELECT SUM(sales_figure) AS SALES, case when device_type ='+QuotedStr('tablet')+'  
       then '+QuotedStr('clPink')+' when device_type ='+QuotedStr('mobile')+' then '+QuotedStr('clBlue')+'  
       then '+QuotedStr('clPink')+' when device_type ='+QuotedStr('mobile')+' then '+QuotedStr('clBlue')+'  
       else '+QuotedStr('clGold')+' end  as color ,  device_type FROM [ProductSales].[dbo].[OperatingSystem
       else '+QuotedStr('clGold')+' end  as color ,  device_type FROM OperatingSystem
       GROUP BY device_type';
       GROUP BY device_type');
       foodListQuery.Open;
       Qry.OpenOrExecute;
       if foodListQuery.Found then
       if (Qry.Found)
       begin
       {
         testChart := MyForm.AddNewChart(MyForm,'testChart','Clomosy Inc');
         Chart1 = MyForm.AddNewChart(MyForm,'Chart1','Clomosy Inc');
         testChart.Charttype := clCSizedPie;
         Chart1.Charttype = clCSizedPie;
         testChart.XAxisText := 'device_type';
         Chart1.XAxisText = 'device_type';
         testChart.ChartItemText := 'Device Sales';
         Chart1.ChartItemText = 'Device Sales';
         testChart.ChartItemsValue := 'SALES';
         Chart1.ChartItemsValue = 'SALES';
         testChart.ChartTitle := 'Clomosy Inc';
         Chart1.ChartTitle = 'Clomosy Inc';
         testChart.clLoadDataFromDataSet(foodListQuery);
         Chart1.clLoadDataFromDataSet(Qry);
       end;
       }
     finally
     except
    foodListQuery.Close;
      ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
      foodListQuery.Free;
     }
     end;
  }
  '''end;'''<br>
 
'''begin'''
  {
     MyForm := TFrmClomosyBasisForm.Create(Self);
   
     SetupSqlConnection;
     MyForm = TclForm.Create(Self);
     AddDataToListview;<br> 
     SqLiteConnectionCreateTable;
     MyForm.Run;<br>
     AddDataToChart;
'''end;'''
   
'''Output:'''<br>
     MyForm.Run;
[[File:ChartClCPie.png|350px|frameless]]
  }
</pre>
 
<b>Output:</b><br>
[[File:ChartClCPie.png|350px|frameless]]<br>
 
<h2> See Also </h2>
* [[Components]]
* [[Object Properties]]
* [[AddNewEvent]]
{{#seo:|title=TclChart Using in Clomosy - Clomosy Docs}}
{{#seo:|description=TclChart is used to create visual data representations like line, bar, pie, and area charts on a form or container.}}

Latest revision as of 13:40, 24 December 2024

AComponent : Specifies the parent of the object to be defined.

xName : The name of the defined chart should be written.

xTitle : You can add a title.

This component, used to create graphics and drawings, can be used on a form or within another container. The TclChart component supports the creation of various data visualizations. These chart types include line charts, bar charts, pie charts, and area charts.

Feature Use of Definition
TClChart Chart1 : TClChart; A variable belonging to the TClChart class is created.
AddNewChart Chart1 = Form1.AddNewChart(Form1,'Chart1','Clomosy Inc'); A new TClChart is added to the form.
Width Chart1.Width = 150; Allows adjusting the width of the chart.
Height Chart1.Height = 50; Allows adjusting the height of the chart.
Align Chart1.Align = alTop; With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the page to learn about these features.
Margins Chart1.Margins.Left = 50; // Right, Top, Bottom With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
TclChartMargins.png

clLoadDataFromJSONStr
clLoadDataFromDataset
Chart1.clLoadDataFromJSONStr(simpleJSONStr); //simpleJSONStr: String;
Chart1.clLoadDataFromDataSet(Qry); // Qry(TclDataSet): TclSQLiteQuery
There are 2 different methods to add data to the TClChart component. With the json structure, data can be added or the data can be added by taking the data over the data set. Examples of these are given at the bottom of the page. Their identification procedures are as follows:
XAxisText Chart1.XAxisText = 'DeviceType'; The x-axis area given for the values ​​to be compared
ChartItemsValue Chart1.ChartItemsValue = 'Percent'; The values ​​of the items entered on the X axis come and the graph is formed over these values.
ChartItemText Chart1.ChartItemText = 'Device Sales'; TIt is the title of graphic elements.
ChartTitle Chart1.ChartTitle = 'Samsoong Inc'; The title of the chart.
Charttype Chart1.Charttype = clCBar; The ChartType parameter is used to change the graphic display. There are 4 graphic views available. Graph view properties definitions:
  • clCLine : Line view.
  • clCBar : It's a bar view.
  • clCPie : It's a pie view.
  • clCSizedPie : It is a sized pie view.

SetAutoXRange - SetAutoYRange Chart1.SetAutoXRange(4);
Chart1.SetAutoYRange(3);
These procedures are used to adjust the automatic ranges of the X and Y axes in a graph. They allow you to enable or disable specific behaviors for determining the axis ranges based on the data displayed on the graph. The parameter values can be set as follows:
  • 0: arDisabled: Automatic range is disabled. This means that axis ranges are set manually and will not be adjusted automatically.
  • 1: arEnabled: Automatic range is enabled. In this case, the data range on the X or Y axis is automatically calculated and adjusted.
  • 2: arEnabledZeroBased: Automatic range is enabled and the axis range is started from zero. This ensures that the axis starts at zero, and the remaining range is calculated automatically.
  • 3: arCommon: A common automatic range is used. This option typically allows for the same range to be used for multiple datasets.
  • 4: arCommonZeroBased: Common range is started from zero. The same zero-based range is used for all datasets.
SetInteractionPanning Chart1.SetInteractionPanning(True); It is used to control panning interaction in graphical components. Panning allows the image within a graph or visualization area to be moved horizontally or vertically. This feature is particularly useful in large datasets, as it enables users to view different parts of the graph effectively.
SetInteractionScaleMode Chart1.SetInteractionScaleMode(2); It is used to control the scaling interaction in a graphical component. This feature determines how users can perform scaling (zoom) interactions within the graph or visualization area. The parameter values can be set as follows:
  • 0: smNone: Scaling interaction is disabled. Users cannot zoom in or out on the graph.
  • 1: smHorizontal: Only horizontal scaling is enabled. Users can zoom in or out on the graph horizontally.
  • 2: smVertical: Only vertical scaling is enabled. Users can zoom in or out on the graph vertically.
XValuesAngle Chart1.XValuesAngle = 20.0; It specifies the angle of the value labels on the X axis. This angle is typically adjusted in degrees.
Legend Chart1.Legend.Visible = True; It is a property that determines the visibility of the legend on the chart. When set to False, the legend becomes invisible on the chart.
Series Chart1.Series.Clear; It allows you to reset the chart by removing the existing data series on the chart.


Example : Usage with JSON Data


 var
   MyForm:TclForm;
   testChart : TClChart;
   simpleJSONStr : String;
 
 { 
   MyForm = TclForm.Create(Self);
   testChart = MyForm.AddNewChart(MyForm,'testChart','Samsoong');
   simpleJSONStr = '[{ "DeviceType": "Notebook","Percent": 50,"color":"clOrange"},{"DeviceType" : "Tablet","Percent": 35,"color":"clPink"},{"DeviceType" : "Phone","Percent": 73,"color":"clTomato"}]';
 
   testChart.Charttype = clCBar;
   testChart.XAxisText = 'DeviceType';
   testChart.ChartItemText = 'Device Sales';
   testChart.ChartItemsValue = 'Percent';
   testChart.ChartTitle = 'Samsoong Inc';
   testChart.clLoadDataFromJSONStr(simpleJSONStr);
   MyForm.Run;
 
 }

Output:
ChartJSOnDataExample.png


Example: Usage with Data Set


  var
    MyForm : TclForm;
    Chart1 : TClChart;
  
  void SqLiteInsertData;
  {
    try
      Clomosy.DBSQLiteQuery.Sql.Text = '
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (1, ''Vista'',''Microsoft Windows'',''tablet'', 200);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''XP'',''Microsoft Windows'',''tablet'', 500);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Microsoft Windows'',''computer'', 104);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Public Beta'',''MacOS'',''computer'', 400);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (2, ''Tiger'',''MacOS'',''tablet'', 350);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Leopard'',''MacOS'',''computer'', 125);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (3, ''Lollipop'',''Android'',''mobile'', 325);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''Android'',''tablet'', 123);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (4, ''Gnome'',''Pardus'',''computer'', 300);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Raspberry'',''Pardus'',''computer'', 175);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (5, ''Tiger'',''MacOS'',''mobile'', 10);
    INSERT INTO OperatingSystem (id, model,operating_system,device_type, sales_figure) VALUES (6, ''Alpha'',''MacOS'',''ipad'', 104);';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      ShowMessage('Adding data to the table was successful!');
    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
  void SqLiteConnectionCreateTable;
  var
    TableExists: Boolean;
  {
    try
      Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProductSales.db3', '');
 
      // Check if the table exists
      Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="OperatingSystem";';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
      
      // Check the results
      TableExists = not Clomosy.DBSQLiteQuery.Eof;
      
      // Create the table if it does not exist
      if not (TableExists)
      {
        Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE OperatingSystem (
                                        	id INTEGER NOT NULL,
                                        	model TEXT NOT NULL,
                                        	operating_system TEXT NOT NULL,
                                        	device_type TEXT NOT NULL,
                                        	sales_figure INTEGER NOT NULL
                                          )';
        Clomosy.DBSQLiteQuery.OpenOrExecute;
        
        ShowMessage('Table successfully added to the database!');
        SqLiteInsertData;
      } else
      {
        ShowMessage('The Products table already exists.');
      }

    except
     ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
    }
  }
  
 void AddDataToChart;
 Var
    Qry : TClSQLiteQuery;
 {
    try
      Qry = Clomosy.DBSQLiteQueryWith('SELECT SUM(sales_figure) AS SALES, case when device_type ='+QuotedStr('tablet')+' 
      then '+QuotedStr('clPink')+' when device_type ='+QuotedStr('mobile')+' then '+QuotedStr('clBlue')+' 
      else '+QuotedStr('clGold')+' end  as color ,  device_type FROM OperatingSystem
      GROUP BY device_type');
      Qry.OpenOrExecute;
      if (Qry.Found)
      {
        Chart1 = MyForm.AddNewChart(MyForm,'Chart1','Clomosy Inc');
        Chart1.Charttype = clCSizedPie;
        Chart1.XAxisText = 'device_type';
        Chart1.ChartItemText = 'Device Sales';
        Chart1.ChartItemsValue = 'SALES';
        Chart1.ChartTitle = 'Clomosy Inc';
        Chart1.clLoadDataFromDataSet(Qry);
      }
     except
      ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
     }
 }
  
  {
    
    MyForm = TclForm.Create(Self);
    SqLiteConnectionCreateTable;
    AddDataToChart;
    
    MyForm.Run;
  }

Output:
ChartClCPie.png

See Also