询价单 中右侧饼图 底部右侧饼图 #1
@ -0,0 +1,183 @@
|
||||
package yem.wmc.ydn.formplugin.dynamic;
|
||||
|
||||
import kd.bos.algo.DataSet;
|
||||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
import kd.bos.form.IFormView;
|
||||
import kd.bos.form.chart.ItemValue;
|
||||
import kd.bos.form.chart.PieChart;
|
||||
import kd.bos.form.chart.PieSeries;
|
||||
import kd.bos.orm.ORM;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import yem.base.common.utils.DateUtil;
|
||||
import yem.base.common.utils.RptUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author power
|
||||
* @ClassName
|
||||
* @description: 中右侧饼图
|
||||
* @date 2024/12/25
|
||||
*/
|
||||
public class CentreRightRrice extends AbstractBillPlugIn implements Plugin {
|
||||
@Override
|
||||
public void afterCreateNewData(EventObject e) {
|
||||
IFormView view = this.getView();
|
||||
Date yearFirst = DateUtil.getLastMonthFirstDay(new Date());
|
||||
view.getModel().setValue("yem_date",yearFirst);
|
||||
setData(view);
|
||||
}
|
||||
@Override
|
||||
public void propertyChanged(PropertyChangedArgs e) {
|
||||
String name = e.getProperty().getName();
|
||||
IFormView view = this.getView();
|
||||
switch (name){
|
||||
case "yem_operator":
|
||||
case "yem_date":
|
||||
setData(view);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void setData(IFormView view){
|
||||
Date yearFirst = DateUtil.getMonthFirstDay((Date) view.getModel().getValue("yem_date"));
|
||||
Date yearLast = DateUtil.getMonthEndDay((Date) view.getModel().getValue("yem_date"));
|
||||
DynamicObject yem_operator = (DynamicObject) view.getModel().getValue("yem_operator");
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
if (null!=yem_operator){
|
||||
|
||||
|
||||
DynamicObject[] result = BusinessDataServiceHelper.load("yem_im_inquiryprice",
|
||||
"yem_commcountryid.name,yem_materialentry,yem_materialentry.yem_material,",
|
||||
new QFilter[]{
|
||||
new QFilter("yem_combofield3", QCP.not_equals,"C"),
|
||||
new QFilter("yem_bizdate",QCP.large_equals,yearFirst),
|
||||
new QFilter("yem_bizdate",QCP.less_equals,yearLast),
|
||||
new QFilter("yem_commcountryid",QCP.equals,yem_operator)
|
||||
});
|
||||
// str = getRandColor(result);
|
||||
// 构建饼图
|
||||
PieChart pieChart = this.getControl("yem_piechartap");
|
||||
pieChart.clearData();
|
||||
pieChart.setShowTooltip(true);
|
||||
PieSeries series = pieChart
|
||||
.createPieSeries("商品种类数量占比"); // 创建饼图系列
|
||||
series.setRadius("0", "100"); // 设置饼图内外半径
|
||||
List<ItemValue> dataList = new ArrayList<>();
|
||||
for(DynamicObject obj:result){
|
||||
// String countryname = obj.getString("countryname");
|
||||
if (map.get(obj.getString("yem_commcountryid.name"))!=null){
|
||||
map.put(obj.getString("yem_commcountryid.name"),map.get(obj.getString("yem_commcountryid.name"))+obj.getDynamicObjectCollection("yem_materialentry").size());
|
||||
}
|
||||
if (map.get(obj.getString("yem_commcountryid.name"))==null){
|
||||
map.put(obj.getString("yem_commcountryid.name"),obj.getDynamicObjectCollection("yem_materialentry").size());
|
||||
}
|
||||
|
||||
// String msg = needtype.equals("A") ?"运营类需求":"项目类需求";
|
||||
// String color = needtype.equals("A") ?"#FFC107":"#00A0E9";
|
||||
// int i = result.indexOf(obj);
|
||||
// ItemValue itemValues = new ItemValue(countryname,obj.getBigDecimal("yem_materialint"),str[i]);
|
||||
// dataList.add(itemValues);
|
||||
}
|
||||
// series.setData(dataList.toArray(new ItemValue[0]));
|
||||
}
|
||||
if (null==yem_operator){
|
||||
// DataSet data = ORM.create().queryDataSet(className,"yem_im_inquiry",
|
||||
// "yem_commcountryid,yem_materialentry.yem_material,yem_materialint",new QFilter[]{
|
||||
// new QFilter("yem_combofield3", QCP.not_equals,"C"),
|
||||
// new QFilter("yem_bizdate",QCP.large_equals,yearFirst),
|
||||
// new QFilter("yem_bizdate",QCP.less_equals,yearLast),
|
||||
// });
|
||||
// DataSet Countrydata = ORM.create().queryDataSet(className,"bd_country","id countryid,name countryname",new QFilter[]{
|
||||
// null});
|
||||
// //连接 最终交单
|
||||
// DataSet dataResult = data.leftJoin(Countrydata).on("yem_commcountryid","countryid")
|
||||
// .select(RptUtil.getDataSetFiledAlias(data), RptUtil.getDataSetFiledAlias(Countrydata)).finish();
|
||||
//
|
||||
// DataSet material = ORM.create().queryDataSet(className,"bd_material","id materialid,name materialname",new QFilter[]{
|
||||
// null});
|
||||
// dataResult = dataResult.leftJoin(material).on("yem_materialentry.yem_material","materialid")
|
||||
// .select(RptUtil.getDataSetFiledAlias(dataResult), RptUtil.getDataSetFiledAlias(material)).finish();
|
||||
// dataResult = data.groupBy(new String[]{"countryname"}).sum("yem_materialint").finish();
|
||||
//// yem_im_inquiry.yem_materialentry.yem_material
|
||||
// DynamicObjectCollection result = ORM.create().toPlainDynamicObjectCollection(dataResult);
|
||||
DynamicObject[] result = BusinessDataServiceHelper.load("yem_im_inquiryprice",
|
||||
"yem_commcountryid.name,yem_materialentry,yem_materialentry.yem_material,",
|
||||
new QFilter[]{
|
||||
new QFilter("yem_combofield3", QCP.not_equals,"C"),
|
||||
new QFilter("yem_bizdate",QCP.large_equals,yearFirst),
|
||||
new QFilter("yem_bizdate",QCP.less_equals,yearLast),
|
||||
// new QFilter("yem_commcountryid",QCP.equals,yem_operator)
|
||||
});
|
||||
// String[] str = getRandColor(result);
|
||||
|
||||
// // 构建饼图
|
||||
// PieChart pieChart = this.getControl("yem_piechartap");
|
||||
// pieChart.clearData();
|
||||
// pieChart.setShowTooltip(true);
|
||||
// PieSeries series = pieChart
|
||||
// .createPieSeries("商品种类数量占比"); // 创建饼图系列
|
||||
// series.setRadius("0", "100"); // 设置饼图内外半径
|
||||
// List<ItemValue> dataList = new ArrayList<>();
|
||||
for(DynamicObject obj:result){
|
||||
if (map.get(obj.getString("yem_commcountryid.name"))!=null){
|
||||
map.put(obj.getString("yem_commcountryid.name"),map.get(obj.getString("yem_commcountryid.name"))+obj.getDynamicObjectCollection("yem_materialentry").size());
|
||||
}
|
||||
if (map.get(obj.getString("yem_commcountryid.name"))==null){
|
||||
map.put(obj.getString("yem_commcountryid.name"),obj.getDynamicObjectCollection("yem_materialentry").size());
|
||||
}
|
||||
// String countryname = obj.getString("countryname");
|
||||
// String msg = needtype.equals("A") ?"运营类需求":"项目类需求";
|
||||
// String color = needtype.equals("A") ?"#FFC107":"#00A0E9";
|
||||
// int i = result.indexOf(obj);
|
||||
// ItemValue itemValues = new ItemValue(countryname,obj.getBigDecimal("yem_materialint"),str[i]);
|
||||
// dataList.add(itemValues);
|
||||
}
|
||||
// series.setData(dataList.toArray(new ItemValue[0]));
|
||||
}
|
||||
String[] str = getRandColor(map);
|
||||
// 构建饼图
|
||||
PieChart pieChart = this.getControl("yem_piechartap");
|
||||
pieChart.clearData();
|
||||
pieChart.setShowTooltip(true);
|
||||
PieSeries series = pieChart
|
||||
.createPieSeries("商品种类数量占比"); // 创建饼图系列
|
||||
series.setRadius("0", "100"); // 设置饼图内外半径
|
||||
List<ItemValue> dataList = new ArrayList<>();
|
||||
int a =0;
|
||||
for (String i : map.keySet()) {
|
||||
ItemValue itemValues = new ItemValue(i,map.get(i),str[a]);
|
||||
dataList.add(itemValues);
|
||||
++a;
|
||||
}
|
||||
series.setData(dataList.toArray(new ItemValue[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成颜色
|
||||
*/
|
||||
public static String[] getRandColor(HashMap<String, Integer> dataMap) {
|
||||
String[] str = new String[dataMap.size()];
|
||||
String r, g, b;
|
||||
for (int i = 0; i < str.length; i++) {
|
||||
Random random = new Random();
|
||||
r = Integer.toHexString(random.nextInt(256)).toUpperCase();
|
||||
g = Integer.toHexString(random.nextInt(256)).toUpperCase();
|
||||
b = Integer.toHexString(random.nextInt(256)).toUpperCase();
|
||||
|
||||
r = r.length() == 1 ? "0" + r : r;
|
||||
g = g.length() == 1 ? "0" + g : g;
|
||||
b = b.length() == 1 ? "0" + b : b;
|
||||
str[i] = "#" + r + g + b;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
package yem.wmc.ydn.formplugin.dynamic;
|
||||
|
||||
import kd.bos.algo.DataSet;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.form.IFormView;
|
||||
import kd.bos.form.chart.*;
|
||||
import kd.bos.form.plugin.AbstractFormPlugin;
|
||||
import kd.bos.orm.ORM;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import yem.base.common.utils.DateUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author power
|
||||
* @ClassName
|
||||
* @description: 底部右侧柱状图
|
||||
* @date 2024/12/26
|
||||
*/
|
||||
public class DownRightPrice extends AbstractFormPlugin implements Plugin {
|
||||
|
||||
@Override
|
||||
public void afterCreateNewData(EventObject e) {
|
||||
super.afterCreateNewData(e);
|
||||
String className = this.getClass().getName();
|
||||
IFormView view = this.getView();
|
||||
Date yearFirst = DateUtil.getLastMonthFirstDay(new Date());
|
||||
view.getModel().setValue("yem_date",yearFirst);
|
||||
List<DynamicObject> data = queyData(view);
|
||||
Map<String, Double> equtypeMap = new HashMap<>();
|
||||
for(DynamicObject object:data){
|
||||
equtypeMap.put(object.getString("yem_commcountryid"),
|
||||
object.getBigDecimal("yem_qty").doubleValue());
|
||||
}
|
||||
if (equtypeMap.size() > 0)HistogramChart(equtypeMap);
|
||||
// HistogramChart(equtypeMap);
|
||||
}
|
||||
|
||||
|
||||
private List<DynamicObject> queyData(IFormView view){
|
||||
|
||||
|
||||
Date yearFirst = DateUtil.getMonthFirstDay((Date) view.getModel().getValue("yem_date"));
|
||||
Date yearLast = DateUtil.getMonthEndDay((Date) view.getModel().getValue("yem_date"));
|
||||
DynamicObject yem_operator = (DynamicObject) view.getModel().getValue("yem_operator");
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
|
||||
DataSet data = ORM.create().queryDataSet("yem_im_inquiryprice","yem_im_inquiryprice",
|
||||
"yem_commcountryid.name yem_commcountryid,yem_materialentry.yem_qty yem_qty",
|
||||
new QFilter[]{
|
||||
new QFilter("yem_combofield3", QCP.not_equals,"C"),
|
||||
new QFilter("yem_bizdate",QCP.large_equals,yearFirst),
|
||||
new QFilter("yem_bizdate",QCP.less_equals,yearLast),
|
||||
// new QFilter("yem_commcountryid",QCP.equals,yem_operator)
|
||||
});
|
||||
data = data.groupBy(new String[]{"yem_commcountryid"}).sum("yem_qty").finish()
|
||||
.orderBy(new String[]{"yem_qty"});
|
||||
DynamicObjectCollection datas = ORM.create().toPlainDynamicObjectCollection(data.copy());
|
||||
List<DynamicObject> result = datas;
|
||||
// List<DynamicObject> result = datas.subList(0, 10);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 柱状图
|
||||
*/
|
||||
private void HistogramChart(Map<String, Double> equtypeMap) {
|
||||
List<String> keysList = new ArrayList<>();
|
||||
List<Number> valuesList = new ArrayList<>();
|
||||
for (Map.Entry<String, Double> entry : equtypeMap.entrySet()) {
|
||||
keysList.add(entry.getKey()); // 添加键
|
||||
valuesList.add(entry.getValue()); // 添加值
|
||||
}
|
||||
Collections.sort(valuesList, (a, b) -> Double.compare(a.doubleValue(), b.doubleValue()));
|
||||
BarChart barchart = this.getControl("yem_histogramchartap");
|
||||
//设置是否显示图例
|
||||
barchart.setShowLegend(true);
|
||||
barchart.setLegendVertical(true);
|
||||
boolean isLegendVertical = true;
|
||||
barchart.setLegendVertical(isLegendVertical);
|
||||
Map<String, Object> titlePropValue = new HashMap<>();
|
||||
// 主标题内容:text
|
||||
titlePropValue.put("text", "区域信息");
|
||||
// 设置触发提示框的类型为axis:坐标轴触发
|
||||
barchart.addTooltip("trigger", "axis");
|
||||
// 字符串模板格式
|
||||
List<Object> toolTipFuncPath = new ArrayList<>();
|
||||
String formatter = "{b0}: {c0}";
|
||||
barchart.addTooltip("formatter", formatter);
|
||||
toolTipFuncPath.add("tooltip");
|
||||
toolTipFuncPath.add("formatter");
|
||||
barchart.addFuncPath(toolTipFuncPath);
|
||||
barchart.setShowTooltip(true);
|
||||
// 设置图例位置为中上
|
||||
barchart.setLegendAlign(XAlign.center, YAlign.top);
|
||||
//AxisType可以调整纵轴或横轴显示数据AxisType.category AxisType.value
|
||||
Axis x = barchart.createXAxis("国家地区", AxisType.category);
|
||||
Axis y = barchart.createYAxis("数量", AxisType.value);
|
||||
Map<String, Object> axisTick = new HashMap<>();
|
||||
axisTick.put("interval", 0);
|
||||
|
||||
y.setPropValue("minInterval", 1);
|
||||
x.setPropValue("data", keysList);
|
||||
x.setPropValue("axisTick", axisTick);
|
||||
BarSeries barseries = barchart.createSeries("");
|
||||
// 设置系列中数据的内容
|
||||
createBarSeries(barseries,valuesList);
|
||||
// barseries.setBarWidth("25px");
|
||||
barchart.refresh();
|
||||
|
||||
|
||||
// //设置是否显示图例
|
||||
// barchart.setShowLegend(true);
|
||||
// boolean isLegendVertical = true;
|
||||
// barchart.setLegendVertical(isLegendVertical);
|
||||
// Map<String, Object> titlePropValue = new HashMap<>();
|
||||
// // 主标题内容:text
|
||||
// titlePropValue.put("text", "条形图");
|
||||
// // 设置触发提示框的类型为axis:坐标轴触发
|
||||
// barchart.addTooltip("trigger", "axis");
|
||||
// // 字符串模板格式
|
||||
// List<Object> toolTipFuncPath = new ArrayList<>();
|
||||
// String formatter = "{b0}: {c0}";
|
||||
// barchart.addTooltip("formatter", formatter);
|
||||
// toolTipFuncPath.add("tooltip");
|
||||
// toolTipFuncPath.add("formatter");
|
||||
// barchart.addFuncPath(toolTipFuncPath);
|
||||
// barchart.setShowTooltip(true);
|
||||
// // 设置图例位置为中上
|
||||
// barchart.setLegendAlign(XAlign.center, YAlign.top);
|
||||
// //AxisType可以调整纵轴或横轴显示数据
|
||||
// Axis x = barchart.createXAxis("国别", AxisType.category);
|
||||
// Axis y = barchart.createYAxis("数量", AxisType.value);
|
||||
// // 设置X轴类目数据(如果没有设置,则需要再series中设置)
|
||||
// String[] data2 = {"中国", "美国", "英国", "法国", "日本"};
|
||||
// x.setPropValue("data", data2);
|
||||
// // 创建系列为“辅助”的系列
|
||||
// BarSeries barseries = barchart.createSeries("辅助");
|
||||
// // 设置系列名称,用于tooltip的显示,legend 的图例筛选.
|
||||
// barseries.setName("来源");
|
||||
// // 设置数据堆叠,同个类目轴上系列配置相同的stack值可以堆叠放置
|
||||
// barseries.setStack("数量");
|
||||
// // 设置系列中数据的内容
|
||||
// Number[] number = {234, 354, 137, 685, 400};
|
||||
// barseries.setData(number);
|
||||
// // 设置柱条颜色(直接设置颜色值和渐变设置)
|
||||
// barseries.setColor("blue");
|
||||
// barchart.refresh();
|
||||
|
||||
}
|
||||
|
||||
private void createBarSeries(BarSeries barSeries,List<Number> values) {
|
||||
|
||||
barSeries.setAnimationDuration(2000);// 动画2秒
|
||||
List<ItemValue> itemValuesList = new ArrayList<>();
|
||||
//根据数据建立不同据条的颜色数据信息
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
Number num = values.get(i);
|
||||
// 偶数基数使用 #496283,奇数基数使用 #1BC85E
|
||||
String color = (i % 2 == 0) ? "#496283" : "#1BC85E"; // 根据索引而不是值来选择颜色
|
||||
ItemValue data = new ItemValue(num, color); // 创建 ItemValue 实例
|
||||
itemValuesList.add(data); // 将 ItemValue 添加到列表
|
||||
}
|
||||
ItemValue[] itemValuesArray = itemValuesList.toArray(new ItemValue[0]);
|
||||
barSeries.setData(itemValuesArray);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user