Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

67
LINES

< > BotCompany Repo | #1002469 // A simpler chart with charts4j

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 180K of libraries. Click here for Pure Java version (1749L/12K/39K).

1  
!759
2  
!1001955 // charts4j
3  
4  
import com.googlecode.charts4j.*;
5  
import static com.googlecode.charts4j.Color.*;
6  
import static com.googlecode.charts4j.Shape.*;
7  
import static com.googlecode.charts4j.UrlUtil.normalize;
8  
import java.awt.Color;
9  
import java.awt.Shape;
10  
11  
static S title = "A Chart!", valuesTitle = "Woot?";
12  
13  
p {
14  
  // Make values
15  
  
16  
  final int NUM_POINTS = 25;
17  
  final double[] values = new double[NUM_POINTS];
18  
  for (int i = 0; i < NUM_POINTS; i++)
19  
      values[i] = (Math.cos(30*i*Math.PI/180)*10 + 50)*i/20;
20  
      
21  
  Line line1 = Plots.newLine(Data.newData(values), com.googlecode.charts4j.Color.newColor("CA3D05"), valuesTitle);
22  
  line1.setLineStyle(LineStyle.newLineStyle(3, 1, 0));
23  
  line1.addShapeMarkers(DIAMOND, newColor("CA3D05"), 12);
24  
  line1.addShapeMarkers(DIAMOND, WHITE, 8);
25  
  
26  
  // Defining chart.
27  
  LineChart chart = GCharts.newLineChart(line1);
28  
  chart.setSize(600, 450);
29  
  chart.setTitle(title, WHITE, 14);
30  
  chart.addHorizontalRangeMarker(40, 60, newColor(RED, 30));
31  
  chart.addVerticalRangeMarker(70, 90, newColor(GREEN, 30));
32  
  chart.setGrid(25, 25, 3, 2);
33  
34  
  // Defining axis info and styles
35  
  
36  
  AxisStyle axisStyle = AxisStyle.newAxisStyle(WHITE, 12, AxisTextAlignment.CENTER);
37  
  AxisLabels xAxis = AxisLabelsFactory.newAxisLabels("Nov", "Dec", "Jan", "Feb", "Mar");
38  
  xAxis.setAxisStyle(axisStyle);
39  
  AxisLabels xAxis2 = AxisLabelsFactory.newAxisLabels("2007", "2007", "2008", "2008", "2008");
40  
  xAxis2.setAxisStyle(axisStyle);
41  
  AxisLabels yAxis = AxisLabelsFactory.newAxisLabels("", "25", "50", "75", "100");
42  
  AxisLabels xAxis3 = AxisLabelsFactory.newAxisLabels("Month", 50.0);
43  
  xAxis3.setAxisStyle(AxisStyle.newAxisStyle(WHITE, 14, AxisTextAlignment.CENTER));
44  
  yAxis.setAxisStyle(axisStyle);
45  
  AxisLabels yAxis2 = AxisLabelsFactory.newAxisLabels("Hits", 50.0);
46  
  yAxis2.setAxisStyle(AxisStyle.newAxisStyle(WHITE, 14, AxisTextAlignment.CENTER));
47  
  yAxis2.setAxisStyle(axisStyle);
48  
49  
  // Adding axis info to chart.
50  
  
51  
  chart.addXAxisLabels(xAxis);
52  
  chart.addXAxisLabels(xAxis2);
53  
  chart.addXAxisLabels(xAxis3);
54  
  chart.addYAxisLabels(yAxis);
55  
  chart.addYAxisLabels(yAxis2);
56  
57  
  // Defining background and chart fills.
58  
  
59  
  chart.setBackgroundFill(Fills.newSolidFill(newColor("1F1D1D")));
60  
  LinearGradientFill fill = Fills.newLinearGradientFill(0, newColor("363433"), 100);
61  
  fill.addColorAndOffset(newColor("2E2B2A"), 0);
62  
  chart.setAreaFill(fill);
63  
  
64  
  String url = chart.toURLString();
65  
  print("URL: " + url);
66  
  showImage(url, "A Chart!");
67  
}

Author comment

Began life as a copy of #1001957

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002469
Snippet name: A simpler chart with charts4j
Eternal ID of this version: #1002469/1
Text MD5: 32444f19d465a576246fe57a87d17f06
Transpilation MD5: 1e3bc7b31e310881328bfd55f590fc64
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-25 03:04:51
Source code size: 2545 bytes / 67 lines
Pitched / IR pitched: No / No
Views / Downloads: 775 / 831
Referenced in: [show references]