Java Implementation Chart Trend chart Show __ Trend chart

Source: Internet
Author: User

Js:

Scoring trends
Progressloadnew ({
Body: ' #lineScore '
});
$.post (basepath + ' pfmreport/getexportreportkpichartscoredata '), {
Dbid:dbid,
Owner:owner,
Table_name:tablename,
Checkrecorderid:flcheckrecordid,
StartTime: $ (' #beginTime '). Datetimebox (' GetValue '),
Endtime: $ (' #endTime '). Datetimebox (' GetValue ')
}, function (data) {
data = typeof data = = ' String '? Json.parse (data): data;

var obj, series = [];
Series.push ({
Name: ' Scoring trend ',
Type: ' line ',
Data:data.data
});
obj = Initbrokenline (' Linescoreview ', data.datelist, ['], series, data. X_axis, data. Y_axis);
settimeout (function () {
Report.score = Obj.getdataurl ();
}, 1000);
Progressclosenew ({
Body: ' #lineScore '
});
});
}


Initializing a line chart
function Initbrokenline (ID, datelist, name, series, X_axis, Y_axis) {
var options = {
ToolTip: {
Trigger: ' axis '
},
Legend: {
Data:name,
},
Xaxis: [{
Type: ' Category ',
Boundarygap:false,
Data:datelist,
Name:x_axis,
}],
YAxis: [{
Type: ' Value ',
Name:y_axis,
}],
Grid: {
X:100,
X2:100,
},
Series:series
};
var echartcolumn = Echarts.init (document.getElementById (id));
Echartcolumn.setoption (options, true);
return echartcolumn;
}




Controller

/**
*
* @param tableId
* @param dbid
* @return
*/
@ResponseBody
@RequestMapping ("/getexportreportkpichartscoredata")
Public map<string, object> getexportreportkpichartscoredata (String dbid,string owner,string table_name,String Checkrecorderid,string starttime,string endtime) {
if (dbid==null| | owner==null| | Table_name==null) {
Logger.error ("Key parameter is null");
return null;
}
map<string, object> data = Pfmreportserviceimpl.getexportreportkpichartscoredata (dbid, Owner,table_name, Checkrecorderid,starttime,endtime);
if (Data.size () >0) {
return data;
}
return null;
}



Service

Propertyhelper propertyhelper = new Propertyhelper (
Pathhelper.getclassespath (This.getclass ()) + "com/snc/hottablemanage/config/export.properties");
int days = Integer.parseint (Propertyhelper.getproperty ("exportdays"));



String temp= "SELECT DISTINCT" +
"A.score," +
"A.timeid," +
"B.flchecktime" +
"From" +
"Htm_pfm_table_score A," +
"Htm_basejob_checkrecords B" +
"WHERE 1=1" +
"and A.flcheckrecordid=b.flid" +
"And A.dbid =?" +
"And A.owner =?" +
"And A.table_name =?";


The start time is not empty
if (Starttime!=null&&!starttime.equals ("")) {
temp+= "and b.flchecktime>= '" +starttime+ "";
}
End time is not empty
if (Endtime!=null&&!endtime.equals ("")) {
temp+= "and b.flchecktime<= '" +endtime+ "";
}

If the date does not pass in, take the distance flchecktime the maximum n days before the record
if (Stringutil.isempty (starttime) &&stringutil.isempty (Endtime)) {
Htmbasejobcheckrecords HBC = Htmbasejobcheckrecordsdaoimpl.get (Htmbasejobcheckrecords.class,long.parselong ( Checkrecorderid));
if (hbc==null| | Hbc.getflchecktime () ==null) {
return null;
}
Date enddate = Hbc.getflchecktime ();
Calendar cal = Calendar.getinstance ();
Cal.settime (EndDate);
EndDate = Cal.gettime ();
Cal.set (Calendar.date, Cal.get (calendar.date)-days);
Date startdate = Cal.gettime ();

SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String Enddate_=sdf.format (EndDate);
String Startdate_=sdf.format (StartDate);

temp+= "and b.flchecktime>= '" +startdate_+ "' and b.flchecktime<= '" +enddate_+ "";
}


map<string,object> result = new hashmap<string,object> ();
Result.put ("X_axis", "Time");
Result.put ("Y_axis", "score");

List<object> params=new arraylist<object> ();
Params.add (dbid);
Params.add (Owner.tostring ());
Params.add (Table_name.tostring ());
list<object[]> list = Htmpfmreportdaoimpl.findbysql (temp, Params.toarray ());


Map<string,object> map=new hashmap<string,object> ();
list<string> datelist = new arraylist<string> ();
list<integer> dataList = new arraylist<integer> ();
For (object[] objects:list) {
String flchecktime=objects[2]==null? "": O Bjects[2].tostring ();
Integer Score=objects[0]==null?0:integer.parseint (objects[0].tostring ());
Map.put (Flchecktime, score);
}

Sort the dates
if (map!=null) {
/* Place map data in list, then sort list by Key of map * *
list<map.entry<string, object>> maplist = new arraylist<map.entry<string, Object>> ( Map.entryset ());
Collections.sort (maplist, New comparator<map.entry<string, object>> () {
public int Compare (map.entry<string, object> O1, map.entry<string, object> O2) {
Return (O1.getkey ()). ToString (). CompareTo (O2.getkey ());
}
});

For (map.entry<string, object> entry:maplist) {
String Date=entry.getkey ();
Integer Score=integer.parseint (Entry.getvalue (). toString ());
Datelist.add (date);
Datalist.add (score);
}


Result.put ("Datelist", datelist);
Result.put ("Data", dataList);
Logger.info ("Rating chart data:" +result);
}
return result;
}


Effect: This figure is only for reference, the specific shape changes according to the data








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.