引用
<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/incubator-echarts-master/dist/echarts.min.js"></script>
页面
<style>
.main {
width: 50%;
height: 500px;
float: left;
}
</style>
<div style="width:100%;">
<div id="analog" class="main"></div>
<div id="switch" class="main"></div>
</div>
js
<script>
$(function () {
var legendanalog = [];
var legendswitch = [];
var seriesanalog = [];
var seriesswitch = [];
$.ajax({
url: '@Url.Action("GetRealTimeAnalogSensorFullNos")',
type: 'get',
data: {},
async: false,
success: function (data) {
if (data != null && data != [] && data.length != 0) {
legendanalog = data;
$.each(data, function (index, element) {
seriesanalog.push({ name: element, type: 'line', data: [] })
})
setInterval(function() {
$.ajax({
url: '@Url.Action("GetRealTimeAnalogData")',
data: { sensorFullNos: legendanalog },
dataType: "json",
type: "get",
traditional: true,
success: function (data) {
var date = new Date();
$.each(data, function (index, element) {
var series = option.series.filter(a => a.name == eleme