如何将echats图表放入一个自定义的弹出窗口中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将echats图表放入一个自定义的弹出窗口中相关的知识,希望对你有一定的参考价值。
//弹出框用easyUI做的,柱状图用echats做的 。看看对你有用不?
<div id="div_AddView" class="easyui-window" closed="true">
<div id="column" style="width: 1000px; height: 550px;display:none ;"></div>
</div>
<script type="text/javascript">
$(document).ready(function ()
init_datagrid();//初始化表
init_window();
data=[name:"南京",hjmj:"26",kq:"30",td:"35",gd:"20",ld:"10",cd:"10",yd:"10",jz:"10",qt:"10" ,
name:"徐州",hjmj:"21",kq:"12",td:"30",gd:"20",ld:"10",cd:"10",yd:"10",jz:"10",qt:"10" ,
name:"苏州",hjmj:"4",kq:"",td:"3",gd:"20",ld:"10",cd:"10",yd:"10",jz:"10",qt:"10" ]
var xData = [];
var datas = [];
var WEIGHT = [];
var GROSSWEIGHT = [];
for (var i = 0; i < data.length; i++) //将json格式转换为Echarts的数组格式
xData.push(data[i].name || ",");
datas.push(data[i].hjmj || ",");
WEIGHT.push(data[i].kq || ",");
GROSSWEIGHT.push(data[i].td || ",");
var chart = document.getElementById('column');
var echart = echarts.init(chart);
var option =
title:
padding:50,
text: '江苏省登记统计数'
,
grid:
x: 100,
y: 100,
borderWidth: 1
,
tooltip:
trigger: 'axis'
,
legend:
padding: 50,
data: ['在建矿山','生产矿山','废弃矿山'],
orient: 'horizontal'
,
calculable: false,
xAxis: [
type: 'category',
data: xData
],
yAxis: [
type: 'value'
],
series: [
name: '在建矿山',
type: 'bar',
data: datas
,
name: '生产矿山',
type:'bar',
data: WEIGHT
,
name: '废弃矿山',
type:'bar',
data: GROSSWEIGHT
,
]
;
echart.setOption(option);
function eConsole(param)
console.log(param);
echart.on("click", eConsole);
);
function init_window()
var width = 800;
var height = 500;
var top = (document.body.clientHeight - height) / 2;
var left = (document.body.clientWidth - width) / 2;
win_add = $("#div_AddView").window(
closed: true,
width: width,
height: height,
top: top,
left: left,
// modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
);
function AddProject() //点击事件,点击弹出Windows框,显示柱状图
win_add.window('setTitle', '区域附件详情');
win_add.window('open');
xianshi();
function xianshi()
$("#column").show();
$("#data").hide();
参考技术A 页面内加载多个图表的时候,页面内需要放置多个div容器,且在创建的时候renderTo的div容器id需要匹配。如果在创建多个图表的时候,发现只创建了一个或者部分图表,说明出现了错误,错误的原因分析如下所示:
1、jQuery.js的版本是否和highchart.js版本一直;
2、highchart.js是不是不支持初始化图表内的某些属性值,简言之就是highchart.js的版本不对。
3、放置图表的div容器不存在或者id写错。
如何使用自定义布局创建对话框弹出窗口?
我正在尝试创建具有自定义布局的对话框弹出窗口,但是我的自定义布局高度和弹出窗口高度不匹配。此外,弹出窗口还隐藏了一个按钮。我该怎么办,如何使弹出窗口的高度与自定义布局匹配?请帮我。我希望我的弹出窗口看起来像这样
但是看起来像这样
我的自定义布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="336dp"
android:layout_height="156dp"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|center"
android:background="@drawable/rectangle"
android:layout_marginBottom="88dp">
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="58dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/bikepic" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="64dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/delivery" />
<TextView
android:id="@+id/biketextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="69dp"
android:layout_marginTop="17dp"
android:background="@drawable/biketextview"
android:gravity="center"
android:text="Bike"
android:textColor="#FFFFFF"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/deliverytextView"
android:layout_width="64dp"
android:layout_height="18dp"
android:layout_marginTop="17dp"
android:layout_marginEnd="64dp"
android:background="@drawable/deliverytextview"
android:gravity="center"
android:text="Delivery"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView7"
android:layout_width="23dp"
android:layout_height="14dp"
android:layout_marginStart="78dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="74"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView5" />
<TextView
android:id="@+id/textView8"
android:layout_width="23dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="80dp"
android:gravity="center"
android:text="39"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView6" />
弹出对话框代码
popAddPost = new Dialog(this);
popAddPost.setContentView(R.layout.pop_up_confirm_pickup);
//popAddPost.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//popAddPost.getWindow().setLayout(Toolbar.LayoutParams.MATCH_PARENT,Toolbar.LayoutParams.WRAP_CONTENT);
popAddPost.getWindow().getAttributes().gravity = Gravity.BOTTOM;
这是我的做法:
private AlertDialog alertDialog;
alertDialog = buildDialog();
alertDialog.show();
private AlertDialog buildDialog()
final AlertDialog dialogBuilder = new AlertDialog.Builder(context).create();
LayoutInflater inflater = LayoutInflater.from(context);
View dialogView = inflater.inflate(R.layout.dialog, null);
dialogBuilder.setView(dialogView);
dialogBuilder.setButton(DialogInterface.BUTTON_NEGATIVE, "CLOSE", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
dialogBuilder.dismiss();
);
return dialogBuilder;
在您的xml中,父布局在ConstraintLayout上使用RelativeLayout LayoutParams
删除android:layout_alignParentLeft="true"
和android:layout_alignParentEnd="true"
ConstraintLayout也不支持layout_gravity
,因此您也可以删除它。
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rectangle"
android:layout_marginBottom="88dp">
代码
popAddPost = new Dialog(this);
popAddPost.setContentView(R.layout.pop_up_confirm_pickup);
Objects.requireNonNull(popAddPost.getWindow()).setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popAddPost.show();
以上是关于如何将echats图表放入一个自定义的弹出窗口中的主要内容,如果未能解决你的问题,请参考以下文章