Uses 180K of libraries. Click here for Pure Java version (4271L/29K/96K).
1 | !7 |
2 | |
3 | lib 1001955 // charts4j |
4 | |
5 | import com.googlecode.charts4j.*; |
6 | import static com.googlecode.charts4j.Color.*; |
7 | import static com.googlecode.charts4j.Shape.*; |
8 | import static com.googlecode.charts4j.UrlUtil.normalize; |
9 | import java.awt.Color; |
10 | import java.awt.Shape; |
11 | |
12 | answer { |
13 | if (jmatchStart("chart", s, m)) exceptionToUser { |
14 | S title = s; |
15 | int width = 300, height = 220; |
16 | |
17 | // Make values |
18 | |
19 | s = m.rest(); |
20 | print("Chart: rest = " + quote(s)); |
21 | |
22 | if (jmatchStart("*", s, m) && isQuoted(m.get(0))) { |
23 | title = unquote(m.get(0)); |
24 | s = m.rest(); |
25 | print("Chart: rest2 = " + quote(s)); |
26 | } |
27 | |
28 | Double base = null; |
29 | if (jmatchStart("base *", s, m)) { |
30 | base = parseDouble(m.unq(0)); |
31 | s = m.rest(); |
32 | } |
33 | |
34 | L<S> tok = asList(s.split(" +")); |
35 | if (!empty(tok)) { |
36 | final int NUM_POINTS = l(tok); |
37 | final double[] values = new double[NUM_POINTS]; |
38 | for (int i = 0; i < NUM_POINTS; i++) |
39 | values[i] = parseDouble(tok.get(i)); |
40 | print("Chart values: " + structure(values)); |
41 | double minValue = base != null ? base : min(values), maxValue = max(values); |
42 | print("Chart: min/max=" + minValue + "/" + maxValue); |
43 | |
44 | Line line1 = Plots.newLine(DataUtil.scaleWithinRange(minValue, maxValue, values), com.googlecode.charts4j.Color.newColor("CA3D05"), ""/*valuesTitle*/); |
45 | |
46 | line1.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); |
47 | line1.addShapeMarkers(DIAMOND, newColor("CA3D05"), 12); |
48 | line1.addShapeMarkers(DIAMOND, WHITE, 8); |
49 | |
50 | // Defining chart. |
51 | |
52 | LineChart chart = GCharts.newLineChart(line1); |
53 | chart.setSize(width, height); |
54 | chart.setTitle(title, BLACK, 14); |
55 | //chart.setGrid(25, 25, 3, 2); |
56 | |
57 | // Adding axis info to chart. |
58 | |
59 | // Let's try this... works with positive values |
60 | chart.addYAxisLabels(AxisLabelsFactory.newNumericRangeAxisLabels(minValue, maxValue)); |
61 | |
62 | |
63 | // Defining background and chart fills. |
64 | |
65 | /* |
66 | chart.setBackgroundFill(Fills.newSolidFill(newColor("1F1D1D"))); |
67 | LinearGradientFill fill = Fills.newLinearGradientFill(0, newColor("363433"), 100); |
68 | fill.addColorAndOffset(newColor("2E2B2A"), 0); |
69 | chart.setAreaFill(fill); |
70 | */ |
71 | |
72 | ret returnImage(chart.toURLString()); |
73 | } |
74 | } |
75 | } |
Began life as a copy of #1002471
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xfasiavlzxuf
No comments. add comment
Snippet ID: | #1002496 |
Snippet name: | Simple Charts Bot (LIVE) |
Eternal ID of this version: | #1002496/3 |
Text MD5: | cd5efde3468e29a384466d4bc7acc04c |
Transpilation MD5: | 215054d786ae2e2a0faa2e4f6ecd734c |
Author: | stefan |
Category: | eleu |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-09 12:01:41 |
Source code size: | 2391 bytes / 75 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 794 / 2512 |
Version history: | 2 change(s) |
Referenced in: | [show references] |