Exemple #1
0
  public static void main(String args[]) {
    int[] values = {
      10, 15, 12, 14, 16, 8, 9, 10, 14, 17, 14, 12, 68, 90, 32, 46, 22, 24, 80, 22, 78, 12, 98
    };
    String[] users1 = {
      "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
      "T", "U", "V", "W"
    };
    int[] users = {
      10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200,
      210, 220, 230
    };
    LineChart lc = new LineChart();
    lc.setTitle("Customized chart using D3JS");

    Date[] dates = new Date[23];

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());
    int numDays = 23;

    // go 30 days back
    c.add(Calendar.DATE, 0 - numDays);

    // start a loop
    for (int i = 0; i < numDays; i++) {
      c.add(Calendar.DATE, i);
      dates[i] = c.getTime();
    }

    // here you have the date array for last 30 days
    //      System.out.println(Arrays.toString(dates));

    Axis x = new Axis();
    Axis y = new Axis();

    x.setTitle("Users"); // optional
    x.setOrient("bottom"); // Optional

    // Use only one of below three function
    // x.setMin(0);		//Optional
    // x.setMax(300);		//Optional
    // x.setDomain(0,300);		//Optional
    //		x.setTickCount(30);

    // x.setData(users);
    x.setData(dates);
    y.setTitle("Values"); // optional
    y.setOrient("left"); // optional
    y.setData(values);

    lc.setxAxis(x);
    lc.setyAxis(y);
    System.out.println(lc.getLineChartCode());
  }