Template talk:Graph:Lines
Add topicThis page used the Structured Discussions extension to give structured discussions. It has since been converted to wikitext, so the content and history here are only an approximation of what was actually displayed at the time these comments were made. |
Updating graphs when data changes
[edit]@Yurik, how can I update a graph when the underlying data has changed? When I preview the article it shows the updated graph, but when I save the article it still shows the old data, despite purging, null edits, and clearing browser caches. --Ahecht (talk) 20:56, 15 February 2019 (UTC)
- It should auto-update after some time... in theory... e.g. a day or two. Yurik (talk) 02:31, 17 February 2019 (UTC)
Still working?
[edit]RESOLVED | |
Lenghty work of debugging. Still unclear if it can re-happen |
The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.
Hi there
Is this template still working? No graph are shown ? Bouzinac (talk) 19:11, 17 June 2019 (UTC)
- Pinging @Yurik Bouzinac (talk) 09:24, 18 June 2019 (UTC)
- I suspect this is due to some issues with the WDQS query service lately. Once it is working ok again, the graph should refresh. Yurik (talk) 23:25, 18 June 2019 (UTC)
- OK. I'll check it time to time whether it is re-working or not.
- A few improvements if it's possible/not too hard to implement :
- mouse over and show the name of serie/number/year/reference
- When too many lines, it might happen to be hard to read, even with a legend.
- Thank you again for your work !
Bouzinac (talk) 13:11, 19 June 2019 (UTC)- Somehow the graphs disappear. They are working in preview mode, but they are not shown live. NGOgo (talk) 19:53, 16 September 2019 (UTC)
- Please report on Phabricator. Very few people see the talk pages when technical issues like this happen. Thanks! Yurik (talk) 20:35, 16 September 2019 (UTC)
- The phabricator is here https://phabricator.wikimedia.org/T226250 Bouzinac (talk) 08:43, 17 September 2019 (UTC)
- For "paintings" example there were faulty data in Wikidata causing long query processing. Population graph data query caused problem as described in https://phabricator.wikimedia.org/T235540 Both are fixed now and working. Pietrasagh (talk) 14:57, 22 November 2020 (UTC)
Change axis, labels, legend, and grid to #54595d grey
[edit]To match Module:Graph for color-inversion consistency, otherwise they all disappear. ~ Tom.Reding (talk ⋅dgaf) 15:04, 1 April 2020 (UTC)
Log scaling
[edit]Is it possible to provide log scaling for the axes? Timbaaa (talk) 02:06, 14 July 2020 (UTC)
- Should be easy to add -- instead of
"type": "linear"
, use a parameter Yurik (talk) 16:50, 14 July 2020 (UTC) - Tried something in Template:Graph:Lines/sandbox, with test case at Template:Graph:Lines/testcases. "0" values are all over the place, I can't figure out how to fix that! Timbaaa (talk) 02:07, 15 July 2020 (UTC)
- @Timbaaa this is expected behavior for 0 values -- see logarithmic scale docs -- all values must be strictly positive (non-zero). There are several things you could do:
- Add a filter transformation to remove all 0 values, right after the "fold" transformation, e.g.
{"type": "filter", "test": "datum.value != 0"}
-- this will remove non-positive values from the data. This would work OK if the 0 values are at the beginning or the end of the line, but if the values are 0 in the middle, it will simply connect the line between last non-zero with the next non-zero, making it appear as if there was always a non-zero value. This might work ok though. I have implemented this change -- see your test case. - Instead of a "filter", add a "formula" transformation that would convert 0 to some positive number, e.g. 1. --
{"type": "formula", "expr": "max(datum.value, 1)", "as": "value"}
Yurik (talk) 04:13, 15 July 2020 (UTC)
- Add a filter transformation to remove all 0 values, right after the "fold" transformation, e.g.
- @YurikThank you for explaining. After going through the docs some time, I have a question, what's the difference between
{"type": "filter", "test": "datum.value != 0"}
and{"type": "filter", "expr": "datum.value != 0"}
? Documentation says "expr" key to use, but here "test" key is used. Just wondering! - Can it be moved to the live module? Timbaaa (talk) 14:53, 15 July 2020 (UTC)
- MediaWiki still uses antique Vega v2 -- see Vega 2 porting guide for the changes. Yurik (talk) 15:03, 15 July 2020 (UTC)
- Ahh, got it! Timbaaa (talk) 15:08, 15 July 2020 (UTC)
- If you are happy with the filtering solution (vs using a small value), sure. Yurik (talk) 15:04, 15 July 2020 (UTC)
- Filtering is enough in this scenario. If 0 is middle of data series, it is better to change it to 1. But, if the whole data series is between 0 and 1, is should anchored to 0.01 or 0.001. Based on the requirement. Timbaaa (talk) 15:14, 15 July 2020 (UTC)
- You could make it a parameter, e.g. `replaceZeroWith` -- if that value is set, it would convert 0s to the given value, and if it is not set, and zType=log, than filter out all 0s. Note that it would not be simple to do both -- to trim 0s at the ends, and replace the values in the middle. Yurik (talk) 15:22, 15 July 2020 (UTC)
- I think `replaceZeroWith` is the way to go. Template documentation can be updated saying, while using log scale `replaceZeroWith` is a required parameter. Now it will only one way(no filtering). Timbaaa (talk) 15:33, 15 July 2020 (UTC)
- I don't think it should be required -- if it is not set, just filter out all the 0s, and if it is set, use it. Yurik (talk) 15:51, 15 July 2020 (UTC)
- I tried it, not sure how to do. Can you help? Timbaaa (talk) 16:30, 15 July 2020 (UTC)
- @Yurik Graph tick marks appears in English on other projects. En and ta both shows the tick marks in english. Where should one add the translations for those? Timbaaa (talk) 11:48, 19 July 2020 (UTC)
- While it could be hacked around by hand, it would need to be modified in the Graph extension code itself to add localization support. Not very difficult, but needs someone to work on it. Yurik (talk) 02:13, 25 July 2020 (UTC)
- Oh, you mean here. I have no clue what so ever :( Timbaaa (talk) 13:06, 25 July 2020 (UTC)
Localization on x axis value
[edit]With reference to tamil template [1] we would like to the know possibilities for translating the Month name at x axis value to Tamil. 2409:4072:6493:737D:6C78:D7CF:50C:D511 (talk) 13:18, 20 July 2020 (UTC)
yMin/yMax and colors
[edit]I am having issues getting the parameters yMax and yMin to work on a type=time
graph - I need 1 to be the y-max, and variable integers >1 to be the y-min. The graph fails to render correctly if using. Also, is it possible to change the colors of individual lines? I placed a test case here: Template:Graph:Lines/testcases#Testing_for_inverted_y-axis Bob247 (talk) 18:31, 18 November 2020 (UTC)
Format numbers
[edit]The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.
Hello, is it possible to somewhere format the separators of numbers according to the locale of the wiki ? Likewise a {{formatnum}} with 10,000,000 in English and 10 000 000 in French, for instance, about the y axis ? Bouzinac (talk) 10:43, 26 December 2020 (UTC)
Colors values
[edit]hello @The RedBurn, except for 'category10', what are the possible values? https://vega.github.io/vega/docs/schemes/ does not look to work. Bouzinac (talk) 12:35, 23 February 2021 (UTC)
- Hi @Bouzinac, they should all work, except that they require a different syntax than the one to set custom colors (like #0000aa,#ff8000,blue,red). I've yet to find a way to make both work at the same time, it probably requires to check for each and every scheme. Color schemes require the "colorscheme" syntax but custom colors require the ["color1","color2","color3"] syntax. An easier way and probably the way to go would be to use an other parameter like colorscheme for the color scheme name, and then make the colors parameter have priority over it. The RedBurn (talk) 13:54, 23 February 2021 (UTC)
- Might be a good pathwork (either having hard coded colours/or a specific colorscheme) Bouzinac (talk) 14:25, 23 February 2021 (UTC)
- I forgot to update my reply, but it's done with colorscheme: Template:Graph:Lines The RedBurn (talk) 14:27, 23 February 2021 (UTC)
- (commented by mistake) U.84-47-17-91 (talk) 12:33, 10 March 2021 (UTC)
Should xAxisMin and xAxisMax crop series viewport?
[edit]I was trying to limit range of years in below chart(s), to make it similar to one (which has x range 1910 - 2020) from w:COVID-19_pandemic_in_Sweden#Additional_data,_charts_and_tables. But unfortunately xAxisMin and xAxisMax only shifted axis itself but not cropped line series. also I was able to set xAxisMin only for type=linear, but for type=year only xAxisMax somehow works.
So my question is - are there any other attributes which could make this chart to render only some smaller (sub) range of initial tabular data? (Sometimes it could be interesting to show some portion of data in details, so I think supporting such feature should be quite useful)
Source code:
{{Graph:Lines | table=Sweden - yearly population and population changes.tab | type=linear | xField=year | series="deaths_total" | yMin=40000 | xMax=2001 | xMin=1800 | title=Births and deaths totals | xAxis=Year | yAxis=Total (men and women) | legend=Observations | colors=#1f77b4, #000 | xTicks=- | width=1024 | yZero=false | xZero=false }} {{Graph:Lines | table=Sweden - yearly population and population changes.tab | type=year | xField=year | series="deaths_total" | yMin=40000 <!-- | xMin=1760Z --> | xMin=-6626966400000 <!-- | xMax=2001Z --> | xMax=978307200000 | title=Births and deaths totals | xAxis=Year | yAxis=Total (men and women) | legend=Observations | colors=#1f77b4, #000 | xTicks=- | width=1024 | yZero=false | xZero=false }}
U.84-47-17-91 (talk) 20:24, 7 March 2021 (UTC)
- Following advises from discussion: w:Template_talk:Graph:Chart#xAxisMax I was abele to use xMin and xMax with type year as
<!-- | xMin=1760Z --> | xMin=-6626966400000 <!-- | xMax=2001Z --> | xMax=978307200000
- But it makes same effect to type=linear chart - x-axis is drawn with shift, but series viewport remains unchanged (no cropping applied).
- Also I've noticed some relevant attribute in w:Template:Graph:Population_history#filter:
"filter": { "label": "Filter expression", "description": "Optionally, filter the data with an expression, e.g. datum.year >= 1900 && datum.year < 2000" }
- Of course for tabletype = "query" it has little sense, but for tabletype = "tab" it could be pretty useful (for showing data partially, instead of always showing entire table) U.84-47-17-91 (talk) 21:03, 8 March 2021 (UTC)
- As I could see vega axis scale clamp property make xAxisMin and xAxisMax behave more like as expected. However even with "clamp": true chart still has some artifacts at let and right side of series area (it seams that it does not crop invisible (left and right) parts of graph but instead collapses them to 1px width vertical lines).
- Add still I believe that having something like filter= datum.year >= 1900 could provide overall more flexible approach. U.84-47-17-91 (talk) 12:35, 10 March 2021 (UTC)
Tooltipping
[edit]Hello, I've read Vega doc and see it is possible to have tooltips. But couldn't put them on with . Could anyone work on that ?
"signals": [{"name": "rightwidth", "expr": "width + padding.right", "init":"400"}, { "name": "tooltip", "value": {}, "on": [ {"events": "group:mouseover", "update": "datum"}, {"events": "group:mouseout", "update": "{}"}
and
"update": { "stroke": {"scale": "color", "field": "key"}, "x": {"scale": "xscale", "signal": "tooltip.category", "band": 0.5}, "y": {"scale": "yscale", "signal": "tooltip.amount", "offset": -2}, "text": {"signal": "tooltip.amount"}, Bouzinac (talk) 15:51, 5 April 2021 (UTC)
Having different scales for data
[edit]Sometimes we have two different columns we want to compare (number of cases vs number of deaths) but one is way bigger than the other. Would it be possible to have different scales for one of them? Theklan (talk) 22:02, 21 September 2021 (UTC)
- @Theklan: , I would use "| yScale = log" option, to switch to log scale Jarekt (talk) 16:55, 19 August 2022 (UTC)
xMin for exact dates
[edit]We have an example of limiting xMin for a year (1985) but, how can it be done for an exact date (1985-3-4)? Theklan (talk) 22:31, 21 September 2021 (UTC)
Explanation switches to French
[edit]In the Template parameters table here, all the descriptions are in English, except for "X axis scale clamp" which says, "Épingle sur l'échelle de l'axe X. Les courbes au delà de cette épingle seront cachées" (and similarly for "Y axis scale clamp"). I am pretty sure that we don't want to switch languages in the middle of an explanation like this. I don't know enough about this template to provide an English translation myself. Metropolitan90 (talk) 14:55, 22 October 2021 (UTC)
Add a tooltip when highlighting a line
[edit]Looking at some graphs generated using this template, I realised that, if the used colours are quite similar, you can't know to which of the series a curve is associated with. . I suggest (but I clearly not able to) to add a simple tooltip when you highlight a curve with the mouse that shows the name of the series. PionCurieux (talk) 13:48, 21 February 2022 (UTC)
Margin when yZero is false and no minimum is specified
[edit]I have a template that I don't want to start at zero, but neither can I specify a minimum because it depends on the data. This graph automatically sets yMinimum to the minimum value in the query. However I would want some margin, because right now it looks this graph hits the bottom (which people automatically interpret as zero despite not being in the axis). Dajasj (talk) 09:19, 15 March 2022 (UTC)
help needed with x axis
[edit]In the graph below
is there a way to display dates on the x-axis. They could be just values of a "month" column corresponding to to the given row number. Jarekt (talk) 16:52, 19 August 2022 (UTC)
- Please ping me when replying. Jarekt (talk) 16:52, 19 August 2022 (UTC)
- @Jarekt, set 'X axis type' to 'time' and 'xField' to a column where you store dates like '2013-02', '2013-03',...
- See Template:Graph:Lines, under 'Template parameters' for more examples and options. RonnieV (talk) 16:17, 11 May 2023 (UTC)
Is it possible to avoid null values?
[edit]I have a dataset where null values are stored as "0". I see that I can safely change them at JSON with "null", but the graph will still show them as "0". Is there any way to avoid those and just break the graph where no data exists? Theklan (talk) 12:42, 12 December 2022 (UTC)
Overflow in mobile view
[edit]I want to apologize ahead of time for my poor English. Now, big graph in mobile view is rendered outside the padding box. Is it able to add scrollbar if content overflows, like Template:Graph:Chart? Thank you, IXTA9839 (talk) 16:29, 17 April 2023 (UTC)