android 用echarts绘制图表(折线与柱状图)

1.首先在echarts官网下载echarts.min.js文件。

2.新建android 项目,把下载完成后把文件放在android项目的assets文件夹下。

3.在assets文件夹下新一个.html的文件,名称自己取。(新建一个file把后缀改成.html就行)

4.在html文件里绘制图形然后在activity里调用,下面把代码贴出来。

view.html(双折线和双柱状图)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>eCharts</title>
    <div id="main"
         style="width: 100%; height: 350px;background-color: #181D31; border-radius: 10px;"></div>
    <div class="mark" style="width: 100%; box-sizing: border-box;padding: 0 30px;color: #ffffff;
    display: flex; justify-content: space-between;position: relative;bottom: 45px;">
        <text class="left" style="font-size: 12px;"></text>
        <text class="right" style="font-size: 12px;"></text>
    </div>
    <script src="./echarts.min.js"></script>
</head>
<body style="margin: 10; padding: 0">
<script type="text/javascript">
			function doCreateChart(type, xData, yData1,yData2) {
			    document.querySelector(".left").innerHTML = "10/01";
			    document.querySelector(".right").innerHTML = "10/02";
				var myChart = echarts.init(document.getElementById('main'));
				var option = {
					animation: false,
					title: {
						text: '睡眠类型',
						padding: 20,
						textStyle: {
							color: '#FFFFFF'
						}
					},
					legend: {
					icon:"circle",
					orient: 'horizontal',
					x:'center',
					y:'bottom',
					padding:[0,0,10,0],
					itemGap:40,
                    data:['浅睡','深睡'],
                    	textStyle: {
							color: '#FFFFFF'
						}
                    },
					tooltip: {
						trigger: 'axis',
						textStyle: {
							fontSize: 8,
							backgroundColor: '#FFFFFF',
							color: "black"
						},
						padding: 5,
						formatter: function(params) {
							var content = "";
							var xName = "时间:";
							var yName1 = "深睡:";
							var yName2 = "浅数:";
							content += xName + params[0].name + '<br/>';
							content += yName1 + params[0].value+ '<br/>';
							content += yName2 + params[1].value;
							return content
						}
					},
					xAxis: {
						type: 'category',
						data: xData,
						axisTick: {
							alignWithLabel: true
						}
					},
					yAxis: {
						type: 'value',
						splitLine: {
						show: true,
						lineStyle: {
							color: ['#AAAAAA'],
							width: 0.5,
							type: 'dashed'
						}
					 },
					},
					series: [{
					    name:'浅睡',
						data: yData1,
						type: type,
						symbolSize: 4,
						symbol: 'circle',
					itemStyle: {
						normal: {
							color: '#5D2EEE', //折点颜色
							lineStyle: {
								color: '#5D2EEE' //折线颜色
							}
						}
					  }
					},{
					name:'深睡',
					data:yData2,
					type: type,
					symbolSize: 4,
					symbol: 'circle',
					itemStyle: {
						normal: {
							color: '#AEF1FF', //折点颜色
							lineStyle: {
								color: '#AEF1FF' //折线颜色
							}
						}
					  }
					}]
				};
				myChart.setOption(option);
			}

</script>
</body>
</html>

 view1.html(单折线与单柱状图)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>eCharts</title>
    <div id="main"
         style="width: 100%; height: 350px;background-color: #181D31; border-radius: 10px;"></div>
    <div class="mark" style="width: 100%; box-sizing: border-box;padding: 0 30px;color: #ffffff;
    display: flex; justify-content: space-between;position: relative;bottom: 45px;">
        <text class="left" style="font-size: 12px;"></text>
        <text class="right" style="font-size: 12px;"></text>
    </div>
    <script src="./echarts.min.js"></script>
</head>
<body style="margin: 10; padding: 0">
<script type="text/javascript">
			function doCreateChart(type, xData, yData1) {
			    document.querySelector(".left").innerHTML = "10/01";
			    document.querySelector(".right").innerHTML = "10/02";
				var myChart = echarts.init(document.getElementById('main'));
				var option = {
					animation: false,
					title: {
						text: '打鼾次数',
						padding: 20,
						textStyle: {
							color: '#FFFFFF'
						}
					},
					tooltip: {
						trigger: 'axis',
						textStyle: {
							fontSize: 8,
							backgroundColor: '#FFFFFF',
							color: "black"
						},
						padding: 5,
						formatter: function(params) {
							var content = "";
							var xName = "时间:";
							var yName = "次数:";
							content += xName + params[0].name + '<br/>';
							content += yName + params[0].value+ '<br/>';
							return content
						}
					},
					xAxis: {
						type: 'category',
						data: xData,
						axisTick: {
							alignWithLabel: true
						}
					},
					yAxis: {
						type: 'value',
						splitLine: {
						show: true,
						lineStyle: {
							color: ['#AAAAAA'],
							width: 0.5,
							type: 'dashed'
						}
					 },
					},
					series: [{
					    name:'打鼾',
						data: yData1,
						type: type,
						symbolSize: 4,
						symbol: 'circle',
					itemStyle: {
						normal: {
							color: '#5D2EEE', //折点颜色
							lineStyle: {
								color: '#5D2EEE' //折线颜色
							}
						}
					  }
					}]
				};
				myChart.setOption(option);
			}

</script>
</body>
</html>

MainActivity里调用

@SuppressLint("SetJavaScriptEnabled")
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val webview = findViewById<WebView>(R.id.webview)
        val webview1 = findViewById<WebView>(R.id.webview1)
        webview.settings.allowFileAccess = true
        webview.settings.javaScriptEnabled = true
        webview.loadUrl("file:///android_asset/view.html")

        webview1.settings.allowFileAccess = true
        webview1.settings.javaScriptEnabled = true
        webview1.loadUrl("file:///android_asset/view1.html")

        val value = arrayOf("12:00", "13:00", "14:00", "15:00", "16:00", "17:00","18:00","19:00","20:00","21:00","22:00","23:00","00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00")
        val xValue= JSONArray(value)
        val yValue1 = arrayOf(5, 20, 36, 10, 10, 20,5, 20, 36, 10, 10, 20,46,150, 20, 36, 10, 10, 200,5, 20, 36, 10, 10, 20,46)
        val yValue2 = arrayOf(15, 60, 108, 30, 30, 60,15, 60, 112, 30, 35, 65,128,223, 60, 145, 36, 32, 268,16, 65, 147, 32, 31, 39,157)

        findViewById<Button>(R.id.bt_linechart).setOnClickListener {
            webview.loadUrl("javascript:doCreateChart('line',$xValue,${yValue1.toList()},${yValue2.toList()});")
            webview1.loadUrl("javascript:doCreateChart('line',$xValue,${yValue1.toList()});")
        }
        findViewById<Button>(R.id.bt_barchart).setOnClickListener {
            webview.loadUrl("javascript:doCreateChart('bar',$xValue,${yValue1.toList()},${yValue2.toList()});")
            webview1.loadUrl("javascript:doCreateChart('bar',$xValue,${yValue1.toList()});")
        }
      /*  findViewById<Button>(R.id.bt_piechart).setOnClickListener {
            webview.loadUrl("javascript:doCreateChart('pie',$xValue,${yValue1.toList()},${yValue2.toList()});")
            webview1.loadUrl("javascript:doCreateChart('pie',$xValue,${yValue1.toList()});")
        }*/
    }
}

activity_main.xml

<?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="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/bt_linechart"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="linechart"
        app:layout_constraintEnd_toStartOf="@id/bt_barchart"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/bt_barchart"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="barchart"
        app:layout_constraintEnd_toStartOf="@id/bt_piechart"
        app:layout_constraintStart_toEndOf="@id/bt_linechart"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/bt_piechart"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="piechart"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/bt_barchart"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/bt_linechart">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            tools:ignore="WebViewLayout">

            <WebView
                android:id="@+id/webview"
                android:layout_width="match_parent"
                android:layout_height="350dp" />

            <WebView
                android:id="@+id/webview1"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                android:layout_marginTop="10dp"
                app:layout_constraintTop_toBottomOf="@id/webview" />
        </LinearLayout>
    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

效果图

 类型:line 是折线,bar 是柱状图,pei是饼状图

用echarts绘制图表需要js语言的基础

API地址:ECharts xAxis配置 x坐标轴刻度_w3cschool

<think>好的,用户需要关于Stable Diffusion提示词使用教程的信息。首先,我需要回忆之前提供的引用内容,看看是否有相关资源。引用[1]提到的是部署教程,引用[2]是关于SD webui的设置和使用,里面可能包含提示词部分。引用[3]主要讲ControlNet插件,可能不直接相关,但训练部分可能有间接联系。 用户可能刚接触Stable Diffusion,需要基础提示词指南,比如结构、语法、权重调整等。根据引用[2],教程里大部分内容来源于该链接,应该详细讲解提示词的使用。需要确认该教程是否涵盖基本元素,如正向和负向提示词,分隔符的使用,权重符号等。 另外,用户可能需要进阶技巧,比如组合使用多个提示词、调整权重、使用特殊符号。可能需要提到逗号分隔、括号调整权重,以及避免冲突的提示词。引用[1]中的教程虽然主要讲部署,但可能包含入门提示词部分,适合新手。 还要考虑用户可能的误区,比如提示词过多或过少,顺序问题,或者语法错误。需要建议用户从简单开始,逐步测试效果。可能还需要推荐其他资源,如提示词手册或社区案例,帮助用户积累经验。 最后,确保回答结构清晰,分点说明,并正确引用来源。检查是否有遗漏的重要信息,比如负向提示词的重要性,或如何利用模型特性优化提示词。确认提供的链接确实包含相关内容,避免误导用户。</think>以下是关于Stable Diffusion提示词使用教程的详细说明: ### 一、提示词基础原理 1. **正向/负向提示词机制** 通过$正向提示词$描述期望生成的内容(如"masterpiece, best quality"),用$负向提示词$排除不需要的元素(如"blurry, deformed")。这种二元控制机制直接影响扩散模型的采样方向[^2]。 2. **语义权重系统** 使用`(提示词:权重值)`语法调整影响强度,例如`(sunset:1.3)`表示增强权重,`(tree:0.7)`表示减弱影响。权重范围建议在0.5-1.5之间。 ```python # 典型提示词结构示例 positive_prompt = "8k,(detailed eyes:1.2),fantasy landscape,glowing runes" negative_prompt = "(low quality:1.1),text,watermark,extra fingers" ``` ### 二、实用技巧 1. **结构化描述法** 按`主体+细节+风格+画质`的层级组织提示词: ``` 1girl, pink hair, (flowing dress:1.3), cherry blossoms, studio ghibli style, unreal engine 5, octane render ``` 2. **特殊控制符** - `[A|B]`交替融合:`[cyberpunk|steampunk] city` - `AND`多主体组合:`cat AND dog on meadow` - `:`动态权重:`(color intensity:1.2:0.8)`表示从1.2渐变到0.8 3. **模型适配策略** 不同模型需配合特定触发词: - NovelAI系列常用`masterpiece, best quality` - Realistic模型需要`photo-realistic, ultra-detailed` - 动漫模型响应`official art, cel-shading` ### 三、进阶应用 1. **艺术家风格移植** 通过`by [艺术家名]+风格关键词`组合实现风格迁移: ``` portrait of knight, intricate armor, by greg rutkowski and alphonse mucha, art nouveau, gold filigree ``` 2. **跨模态引导** 结合ControlNet插件时,提示词需要控制图对齐: ``` // 线稿上色案例 正向提示词:vibrant watercolor, (soft shading:1.1) ControlNet设置:lineart_anime预处理器,权重0.8 ``` ### 四、资源推荐 1. 官方文档中的提示词工程章节 2. 《AI绘画提示词手册》收录2000+常用词条 3. Lexica.art网站可搜索数千万条生成案例及对应提示词
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值