Skip to content

Instantly share code, notes, and snippets.

@bchetty
Created March 25, 2016 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bchetty/12a80a5ba32c5c2bbd28 to your computer and use it in GitHub Desktop.
Save bchetty/12a80a5ba32c5c2bbd28 to your computer and use it in GitHub Desktop.
Highcharts Chart Controller
package com.bchetty.charts.controller;
import com.bchetty.charts.model.Series;
import com.google.gson.Gson;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Chart Controller
*
* @author Babji Prashanth, Chetty
*/
public class ChartController {
private String chartData;
private String categories;
private List<String> categoryList = new ArrayList<String>();
private List<Long> heapSizeList = new ArrayList<Long>();
private List<Long> usedHeapSizeList = new ArrayList<Long>();
SimpleDateFormat sdfDate = new SimpleDateFormat("HH:mm:ss");//dd/MM/yyyy
private static final long MB = 1024*1024;
int index = 0;
private Long[] longs;
/**
* Load Chart Data
*/
public void loadChartData() {
if(heapSizeList.size() > 10) {
heapSizeList.remove(0);
usedHeapSizeList.remove(0);
categoryList.remove(0);
}
List<Series> series = new ArrayList<Series>();
malloc();
long heapSize = Runtime.getRuntime().maxMemory();
heapSizeList.add(heapSize/MB);
usedHeapSizeList.add((heapSize - Runtime.getRuntime().freeMemory())/MB);
series.add(new Series("Heap Size", heapSizeList));
series.add(new Series("Used Heap", usedHeapSizeList));
setChartData(new Gson().toJson(series));
categoryList.add(sdfDate.format(new Date()));
System.out.println(categoryList);
setCategories(new Gson().toJson(categoryList));
}
/**
* @return the chartData
*/
public String getChartData() {
return chartData;
}
/**
* @param chartData the chartData to set
*/
public void setChartData(String chartData) {
this.chartData = chartData;
}
/**
* @return the categories
*/
public String getCategories() {
return categories;
}
/**
* @param categories the categories to set
*/
public void setCategories(String categories) {
this.categories = categories;
}
private void malloc() {
if(index%2 == 0) {
longs = new Long[100000];
for(int i=0;i<1000;i++) {
longs[i] = Long.valueOf(i);
}
} else {
longs = null;
}
index++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment