C# 在WPF 嵌入 百度ECharts ---婷婷小姐姐 隨手筆記
在網上下載echarts外掛 和你想要的樣式
1、在html頁面新增
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="main" style="width:600px;height:350px" />
<script src="echarts.js"></script>
<script src="walden.js"></script>
<script>
myChart = echarts.init(document.getElementById('main'),"walden");
option = {
title: {
text: {
data: [""]
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
legend: {
data: [""]
},
toolbox: {
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar', 'tiled'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
boundaryGap: false,
data: [""]
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
name: 'A級告警',
type: 'line',
stack: '總量',
areaStyle: { normal: {} },
data: [0]
},
{
name: 'B級告警',
type: 'line',
stack: '總量',
areaStyle: { normal: {} },
data: [0]
},
{
name: 'C級告警',
type: 'line',
stack: '總量',
label: {
normal: {
show: true,
position: 'top'
}
},
areaStyle: { normal: {} },
data: [0]
}
]
};
if (option && typeof option === "object") {
GetReport();
function Request(strName) {
var strHref = location.search;
var intPos = strHref.indexOf("?");
var strRight = strHref.substr(intPos + 1);
var arrTmp = strRight.split("&");
for (var i = 0; i < arrTmp.length; i++) {
var arrTemp = arrTmp[i].split("=");
if (arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
}
return "";
}
function GetReport() {
var type = Request("type");
var title = Request("title");
var result = eval('(' + window.external.GetReportDataAjaxData(title, type) + ')');
//var options = myChart.getOption();
option.title.text = result.title;
option.xAxis[0].data = result.category;
option.series = result.series;
option.legend.data = result.legend;
myChart.setOption(option);
window.onresize = myChart.resize;
}
}
</script>
</body>
</html>
2、新建一個類 書寫方法 GetReportDataAjaxData。
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisible(true)]//給予許可權並設定可見
public class DataAnalysisColumn
{
/// <summary>
/// 最大值、最小值、平均值 的資料分析圖
/// </summary>
/// <param name="title"></param>
/// <param name="type"></param>
/// <param name="alias"></param>
/// <returns></returns>
public string GetReportDataAjaxData(string title, string type, string alias){}
3、頁面呼叫
效果圖:
初學者 忘指點。還有地方可以優化的。轉發請註明出處