代码拉取完成,页面将自动刷新
<%@page import="com.ReadFileUtil" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<%@page import="org.apache.hadoop.fs.FSDataInputStream" %>
<%@ page language="Java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<% List<String> ll =
ReadFileUtil.ReadFromHDFS("hdfs://master:9000/out/view2/part-00000");%>
<script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
</head>
<body>
<div class="chart" id="main" style="width: 900px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '最大代理人TOP20'
},
tooltip: {},
legend: {
data: ['票数']
},
xAxis: {
data: ["<%=ll.get(0)%>"<%for(int i=1;i<40;i++){
if(i%2==0){
%>, "<%=ll.get(i)%>"
<%
}
}
%>]
},
yAxis: {},
series: [{
name: '票数',
type: 'bar',
data: [<%=ll.get(1)%>
<%for(int i=2;i<40;i++){
if(i%2==1){
%>, <%=ll.get(i)%>
<%
}
}
%>]
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
<h2 color="red"><a href="index.jsp">返回</a></h2>
</body>
package com;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Tuple2;
public class MoneyByDay {
public static void main(String[] args) throws Exception {
try {
// spark://master:7077
// yarn-client
SparkConf conf=new SparkConf().setAppName("TicketsCount3").setMaster("local[3]");
JavaSparkContext sc = new JavaSparkContext(conf);
/**
* 数据初步清理,主要是过滤出各个机场个总票数
*/
JavaRDD<String> lines = sc.textFile("hdfs://master:9000/user/data/region.csv", 1);
lines = lines.filter(line ->
line.split(",")[1].substring(0, 1).equals("C") &&
line.split(",")[0].equals("21")
);
JavaPairRDD<String, Integer> pair = lines.mapToPair(line ->
new Tuple2<>(line.split(",")[1], Integer.parseInt(line.split(",")[4]))
);
JavaPairRDD<String, Integer> counts = pair.reduceByKey((v1, v2) -> (v1 + v2));
/**
* 数据二次清理,进行排序
*/
JavaPairRDD<Integer, String> counts_r = counts.mapToPair(t -> new Tuple2<>(t._2, t._1));
JavaPairRDD<Integer, String> sorted_counts_r = counts_r.sortByKey(false);
JavaPairRDD<String, Integer> sortedcounts = sorted_counts_r.mapToPair(t -> new Tuple2<>(t._2, t._1));
sortedcounts.foreach(t -> {
System.out.println(t._1 + "appears " + t._2 + " $.");
});
sortedcounts.saveAsTextFile("hdfs://master:9000/out/view3");
sc.close();
}catch (Exception ex){
ex.printStackTrace();
}
}
}
<%@page import="com.ReadFileUtil" %>
<%@page import="java.util.List" %>
<%@page import="java.util.ArrayList" %>
<%@page import="org.apache.hadoop.fs.FSDataInputStream" %>
<%@ page language="Java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<% List<String> ll =
ReadFileUtil.ReadFromHDFS("hdfs://master:9000/out/view3/part-00000");%>
<script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
</head>
<body>
<div class="chart" id="main" style="width: 900px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: '第21天各机场销售额的Top20'
},
tooltip: {},
legend: {
data: ['销售额']
},
xAxis: {
data: ["<%=ll.get(0)%>"<%for(int i=1;i<40;i++){
if(i%2==0){
%>, "<%=ll.get(i)%>"
<%
}
}
%>]
},
yAxis: {},
series: [{
name: '销售额',
type: 'bar',
data: [<%=ll.get(1)%>
<%for(int i=2;i<40;i++){
if(i%2==1){
%>, <%=ll.get(i)%>
<%
}
}
%>]
}]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
<h2 color="red"><a href="index.jsp">返回</a></h2>
</body>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。