JavaFx BarChart ("Browser/OS choices of Wikimedia users")
Wikimedia released data about Wikimedia projects you can check the list of data sets here.Yeah and its free.So being a javafx enthusiast and my friends saying i have a thing with bar charts well had to play around with the data set browser choices of Wikimedia users the file format is TSV tab separated values ,that makes it very easy to use.
The data is divided into four files desktop editors,desktop readers,mobile editors and mobile readers recorded in 90 days. Read here to see the data collection process used. i.e Ratio
A snapshot of the data
I wanted to display the data as it is ,but that made no difference so i decided to do away with all the os_major,browser_major and percentage .
Working with the new data set still there was repetitiveness in OS cause of the different OS version
I took the major two operating system companies Mac and Windows and check what browsers do they have.
Reading the file is simple as
Path paths=Paths.get(FILE_NAME);
List<String> lines=Files.readAllLines(paths);
The query
int chrome_total_pageviews=0;
for(String s:lines){
String[] item = s.split("\t");//tab separated values
String os=item[0];//get the first value
String browser=item[2];
if(os.startsWith("Windows")){
if(browser.startsWith("Chrome")){
chrome_total_pageviews+=Integer.parseInt(item[4]);//add all pageviews
}
//add other browsers
}
}
XYChart.Series ser_win=new XYChart.Series<>();
ser_win.setName("Windows");
ser_win.getData().add(new XYChart.Data<>("chrome",chrome_total_pageviews));
bar_chart.getData().add(ser_win);
The query simply means if the OS is Windows get me the browsers in this case Chrome and add all the total page views.add the total page views to your XYChart.Series the code can be reused for all files cause they have the same format.
If you don't know how to set up the bar_chart check my previous post
The results
Desktop Readers vs Desktop Editors
Mobile Readers
Mobile Editors
The data is divided into four files desktop editors,desktop readers,mobile editors and mobile readers recorded in 90 days. Read here to see the data collection process used. i.e Ratio
A snapshot of the data
I wanted to display the data as it is ,but that made no difference so i decided to do away with all the os_major,browser_major and percentage .
I took the major two operating system companies Mac and Windows and check what browsers do they have.
Reading the file is simple as
Path paths=Paths.get(FILE_NAME);
List<String> lines=Files.readAllLines(paths);
The query
int chrome_total_pageviews=0;
for(String s:lines){
String[] item = s.split("\t");//tab separated values
String os=item[0];//get the first value
String browser=item[2];
if(os.startsWith("Windows")){
if(browser.startsWith("Chrome")){
chrome_total_pageviews+=Integer.parseInt(item[4]);//add all pageviews
}
//add other browsers
}
}
XYChart.Series ser_win=new XYChart.Series<>();
ser_win.setName("Windows");
ser_win.getData().add(new XYChart.Data<>("chrome",chrome_total_pageviews));
bar_chart.getData().add(ser_win);
The query simply means if the OS is Windows get me the browsers in this case Chrome and add all the total page views.add the total page views to your XYChart.Series the code can be reused for all files cause they have the same format.
If you don't know how to set up the bar_chart check my previous post
The results
Desktop Readers vs Desktop Editors
Mobile Readers
Mobile Editors
Comments
Post a Comment