Using Delphi TChart to display information from a database - sql

I want to create a pie chart in Delphi that will show the user the number of people who play a specific sport.
The following SQL statements gets the information from the database and stores the number of people in a variable. The data type in the database is yes/no, so those who play a specific sport will have a tick and those who don't won't. The sql statement will determine how many people play a specific sport (if there is a tick in the database)
qry.sql.clear;
qry.sql.add('SELECT Count(tennis) AS [NoTennis] FROM [Sports] WHERE Tennis = True');
qry.Open;
iTennis := qry['NoTennis']; {integer variable}
This repeats for all the other sports, such as swimming, hockey, etc
Afterwards this data must be represented in the pie chart. I have the following code...
Chart1.Series[0].AddXY(iTennis, 1, 'Tennis', clTeeColor);
This also obviously repeats for all the other sports. But instead of displaying my data during run time, it still displays random data about keyboards and motorists, etc. To see what I am talking about click
(source: asiplease.net)
How do I get TChart to change it's data? Is it the SQL statement or adding the x and y values that is causing the problem?

You are showing a pie chart. The chart type is relevant how you add data to the chart. I remember thas AddXy was only for line-based chart. Try
Chart1.Series[0].Add(123, 'Tennis');
See steema documentation.
To clear previously generated values of the series, use
Chart1.Series[0].Clear();

Related

How to Write a Variable for a Pie Chart with Multiple Fields in Qlik Sense

I am looking for some help in regards to writing a variable for a Pie Chart on my dashboard. I currently have the following variable for a KPI chart and this shows the latest weeks value but has the flexibility to change if a different week is selected.
=Sum({<week_date ={">=$(=Weekstart(max(week_date)))<=$(=Weekend(max(week_date)))"}>}total_calls)
Now for my pie chart, I want to show the different type of work that has been worked on during the week and this is through the 'source' column which has the following types. This will be my dimension(slice).
SOURCE
Calls
Email
Offline
The measure will show the number of 'touches' and is then displayed as a %. This works if I put the fields in, but I would like to write a variable so that it is dynamic but not sure how I do that.
Would appreciate any advice on how to move this forward.
UPDATES
I have the following values for the latest week (week ending) 21/02/2020:
Calls | 8,477
Email | 4,040
Offline | 9,052
and would like to show this in a Pie Chart. Currently I have managed to write the following definition:
=Sum({<[w_c.week_date] ={">=$(=Weekstart(max([w_c.week_date])))<=$(=Weekend(max([w_c.week_date])))"}>}[w_c.touches])
but I get a total instead of the individual sums for the Sources even though I have selected the SOURCE as the DIMENSION.
SOURCE | $(vVariable)
Calls | 21,569
Email | 21, 569
Offline | 21,569
Any ideas on how I can fix this?
I have added my table view as well as how I am able to get the figures manually if I select the source and week_date column as the dimension and the touches as the measure. If I filter for the latest week it shows me the volumes I want, but I would like this to work dynamically through the use of a variable. I have attached an image showing this, numbers will be different to the above as these have been updated.
I have managed to fix this by removing the "=" from my expression and this gave me the correct individual figures.
=Sum({<[w_c.week_date] =
to
Sum({<[w_c.week_date] = ...

Updating selected data in table/form on change of a field in form with a variable

I'm quite new to MS Access, but I'm trying to set up a database for building management and regulation in MS Access, which is going to be used for energy use modelling of the building. I therefore have multiple tables which i control with forms. There are multiple zones in a building with different occupations, e.g. one zone is offices, the other a recreational area. In those zones are multiple rooms which have the same occupation. I have a form which provides an overview of the zone, with data such as area size, floor nr etc., but also with a list of rooms that are in that zone. The zones with respective occupation and other data are in one table, the list of rooms is a different table.
What I want it to do, is that when I change the occupation of a zone in the overview form, all the rooms in that zone also change to that occupation.
Info:
Zones table contains fields 'Zone_code', 'Occupation' and non related zone specific data
Rooms table contains fields 'Room_ID', 'In_zone', 'Occupation', and room specific data
I've tried using macro's on the 'Onchange' event, where I would select the table, select the data where the zone are equal, and than set the value to the changed occupation. I've also tried it with selecting the subform of the roomlist. I've also tried using an update query, but I encountered errors updating using a variable.
I had to do the same for the floors, where there are multiple zones per floor and have a table for that overview. I'll show the macro that worked there, but when I used a similar one for the rooms, I got errors such as 'The object doesn't contain the Automation object "Roomlist"'. I even tried update queries but I feel lost.
The macro that worked for the floors where 'main' is the main building table with the floors:
https://imgur.com/a/3rED1Pw
The macro i used for the rooms:
https://imgur.com/gvMDIzq
I used the iif statement to compare zones and only update if the zones are the same but this macro crashes, other macro's i made only added 1 new room with the new occupation, but nothing else.
I expected the macro to just run down the table of the rooms and change the value of the ones where the zone code is the same. Or at least, that is what i hope the database will do eventually.
Can somebody help me figure this out so that it works? I feel I'm missing or overlooking one small thing but I don't understand access enough yet to figure out what. I don't mind if the solution uses a completely different aspect of access, as long as it works. Thanks in advance
Let me start out by saying welcome to the site and MS Access! To answer your question, I would start by looking at your data setup. As mentioned by June7, having Occupation in both tables independently is not necessary. Think of it this way: if I have a value I want to update (such as in this case with your question), it is much easier to update in one location than in multiple locations. From what you've shared, [Occupation] only applies to the [Zone_Code] table and should be present only in that table. Through the relationship of [Zone_code] to [Room_ID] through the [In_Zone] field, [Occupation] of the zone that the room is part of can now be queried.
Another thing to consider is having a table, say 'tbl_Occupation' or something of the like, where you could have the fields [OccupationID] and [Occupation]. Doing this could make it easier to maintain the occupations for which a zone can be assigned (if the reference name of an occupation changes but it is not a different occupation, etc.), and also stores occupation in one location, so that if an occupation is assigned to multiple zones, the ID is referenced instead.
I hope this helps!

Grand totals row not summing in Google Data Studio

Well, I'm absolute newbie in Google Data Studio, but for any reason, my grand totals rows is not working.
I'm learning to use this tool, and I made an easy table with just countries and sessions.
Piece of Cake. Now I just want to add a total row where it sums all sessions. That's all. I activated option Show Summary Row but it shows nothing.
Thing's I've done and not worked:
Update and refresh
Changed time period and tried different dates just in case.
Delete and create again full table.
Checked connection. I get data and the data is right, I just cannot sum it.
Changed size and format of table, just in case it where a problems or margins or font color.
And I know it can be done, because different sources. I've read this question here:
Grand Total is wrong in Google Data Studio
But it did not help. In that question, a user posted an image in the comments:
As you can see, he managed to get what I'm trying to do.
So I must be doing something wrong, and I do not why.
UPDATE 2: If I apply a filter, I get no totals. You can see my config in the right side of image.
Can anybody give me a clue of how to make a grand totals row in Google Data Studio?
Thanks
Sounds like a bug. It should be a case of selecting that tick box. Strangely, I looked at an existing table I have with totals and when I unticked the box and then ticked again, the totals didn't reappear and disappeared off another table on the page (like your example). They did reappear eventually with some refreshing of the data and page but seems like there's something wrong with them.
I don't think this is a bug I think it part of the design.
I actually just discovered the reason this is happening at least for me, it doesn't actually sum the values in the table, the grand total summary of a table is a sum of whatever the metric being used is not the actual rows shown in the chart. so if you have a dimension (like age / gender) where there is data thresholding applied internally by google but are using a metric such as users you will see the grand total from the metric value without the thresholding applied from the dimension.
Proof below
You can see the grand total for column 2 is not 953.6 its 453.6 and if i look at a non threshold dimension (country)
you can see where the 953.6 comes from since the data source supplied to the table uses 80% of all users 1192 * .8 give me 953.6 which is what the grand total is displaying. Conclusion, the only way this number could be possible is if, when using a threshold dimension for a table with metric there will be a discrepancy since the grand total value is not coming from the table values but rather from metric source data, which will not have the tables dimension applied for some odd reason.

Categorical Variable content in world map in tableau

I have listed a sample data set. I need to get details of the different elements in the categorical variable over the map while hovering over the countries.
--Dragging and dropping the categorical variable just displays the values for the first element.
the variables used are:
country (geographic)
sales (numeric)
furniture (containing 'table' and 'chair')
I need to get details of sales of chairs and tables over the country on the map while hovering over the countries.
Thanks for the help
the sample data set as seen in the image
I would use the creating a graph in a tooltip hack to solve this problem. The issue is that the Level of Detail of your data does not support the visualisation you want to make.
Do the following:
1) Create cohort calculated fields: You need to separate a measure so that it is specific to one member in a dimension (basically a cross tab).
For you this means creating a calculated field per furniture type.
e.g. Chair Sales Cohort =
if [Furniture] = 'chair'
then [Sales]
END
Repeat this for each furniture type
You can then drag each of these onto the tooltip pane and you will have tooltips :)
If you wanted to get fancy follow step 2 and 3 from this link to make it a bar chart instead of just a number in a tooltip. make a bar chart in tableau
Good luck !

Two Datasets one query

I am trying to create a report using two datasets.
The first has a user id which i need to link to the second one to pull the information required. The second dataset query needs the user.id before the query will work Is there anyway i am able to do this.
Thanks
Can you explain your scenario little clear. Are you trying to have a cascaded parameters in SSRS reports? Say, You need to select a Product from the dropdown (Bat, Ball, Nets etc) and depending on the selection another dropdown will be loaded with the relevant data say (For Ball - Basket ball, Volley ball, Foot ball etc)
You will need to create a subreport and from there pass the user id that is returned from the first dataset into the subreports parameter.
If you have not used subreports, here are some articles: (Assuming you are using Crystal Reports)
http://blog.niklasottosson.com/?p=1137