1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <html>
<head> <script type="text/javascript" src="static/loader.js"></script> <script type="text/javascript"> google.charts.load('current', { 'packages': ['corechart'] });
fetch('static/pi_data.json') .then(response => response.json()) .then(data => { var drawChart_callback = drawChart(data.data, "chart", data.title, data.left_label, data.right_label); google.charts.setOnLoadCallback(drawChart_callback); }) .catch(error => { console.error('读取JSON文件时出错:', error); }); function drawChart(data_arr, chart_id, title, left_label, right_label) { return function () { var data = google.visualization.arrayToDataTable(data_arr);
var options = { hAxis: { useFormatFromData: true, viewWindow: null, minValue: null, maxValue: null, viewWindowMode: null, }, legacyScatterChartLabels: true, vAxes: [{ "useFormatFromData": true, "viewWindow": { "max": null, "min": null }, "minValue": null, "maxValue": null, "title": left_label, "logScale": false, }, { "useFormatFromData": true, "viewWindow": { "max": null, "min": null }, "minValue": null, "maxValue": null, "title": right_label, "logScale": false, }], booleanRole: "certainty", lineWidth: 2, legend: "top", title: title, fontName: "sans-serif", useFirstColumnAsDomain: false, titleTextStyle: { "color": "#000", "fontSize": 24, "bold": true }, series: { "1": { "targetAxisIndex": 1 } }, curveType: "", interpolateNulls: true, series: { "2": { "targetAxisIndex": 1 } } }; var isDefaultVisualization = true; var chart = new google.visualization.LineChart(document.getElementById(chart_id));
chart.draw(data, options, isDefaultVisualization); } } </script> <style> .container { display: flex; flex-wrap: wrap; }
.chart { flex-basis: 50%; width: auto; height: 400px; } </style> </head>
<body> <div id="chart" class="chart"></div> </body>
</html>
|