因此,我嘗試解決此問題一週後我無法完成。 我有這個表:用我的表格中的某些值製作圖表
<table id= "myTable" style="width:100%">
<tr class="val">
<th>value</th>
@for((c,w)<- map){
<td>@c</td>
}
</tr>
<tr class="timp">
<th>time</th>
@for(k <- timeList){
<td> @k</td>
}
</tr>
<tr class="data">
<th>date</th>
@for(q <- dateList){
<td>@q </td>
}
</tr>
</table>
它看起來是這樣的:
我要畫一個圖表。 ... 而在x
斧頭我想有我的約會,和我的小時......和在我的價值觀y
。
我想通過我的td
元素循環......我嘗試了很多圖書館的......但我不能讓我的數據...
例如,現在我與amchart插件播放。我有這樣的代碼:
<script src="@routes.Assets.at("javascripts/amcharts.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/serial.js")" type="text/javascript"></script>
...
<script type="text/javascript">
var chart;
var chartData = [];
AmCharts.ready(function() {
// first we generate some random data
generateChartData();
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "@routes.Assets.at("images/images/")";
chart.dataProvider = chartData;
chart.categoryField = "date";
// data updated event will be fired when chart is first displayed,
// also when data will be updated. We'll use it to set some
// initial zoom
chart.addListener("dataUpdated", zoomChart);
// AXES
// Category
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = true; // in order char to understand dates, we should set parseDates to true
categoryAxis.minPeriod = "mm"; // as we have data with minute interval, we have to set "mm" here.
categoryAxis.gridAlpha = 0.07;
categoryAxis.axisColor = "#DADADA";
// Value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.gridAlpha = 0.07;
valueAxis.title = "Things Chart";
chart.addValueAxis(valueAxis);
// GRAPH
var graph = new AmCharts.AmGraph();
graph.type = "line"; // try to change it to "column"
graph.title = "red line";
graph.valueField = "visits";
graph.lineAlpha = 1;
graph.lineColor = "#d1cf2a";
graph.fillAlphas = 0.3; // setting fillAlphas to > 0 value makes it area graph
chart.addGraph(graph);
// CURSOR
var chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorPosition = "mouse";
chartCursor.categoryBalloonDateFormat = "JJ:NN:SS, YYYY-MM-DD";
chart.addChartCursor(chartCursor);
// SCROLLBAR
var chartScrollbar = new AmCharts.ChartScrollbar();
chart.addChartScrollbar(chartScrollbar);
// WRITE
chart.write("chartdiv");
});
// generate some random data, quite different range
function generateChartData() {
// current date
var firstDate = new Date();
// now set 1000 minutes back
firstDate.setMinutes(firstDate.getDate() - 1000);
// and generate 1000 data items
for (var i = 0; i < 1000; i++) {
var newDate = new Date(firstDate);
// each time we add one minute
newDate.setMinutes(newDate.getMinutes() + i);
// some random number
var visits = Math.round(Math.random() * 40) + 10;
// add data item to the array
chartData.push({
date: newDate,
visits: visits
});
}
}
// this method is called when chart is first inited as we listen for "dataUpdated" event
function zoomChart() {
// different zoom methods can be used - zoomToIndexes, zoomToDates, zoomToCategoryValues
chart.zoomToIndexes(chartData.length - 40, chartData.length - 1);
}
</script>
<div class="row">
<div class="col-md-11">
<div id="chartdiv" style="width:100%; height:400px;"></div>
</div>
</div>
在function generateChartData()
我試圖從我的表中選擇值...但是當我通過我的元素循環 - 圖表消失...這意味着我沒有做正確的...在這裏我有隨機元素的例子,因爲我認爲我的代碼它不好,也許這有助於...
那麼,我該怎麼做?可以做到嗎?
謝謝!
這是我講的......也許你們當中有些人玩它圖表...
但是,任何其他它會成功這將是對我好方法...
當你調用'chart.write(「chartdiv」);'時,你需要在ID的字體中加一個#號嗎?所以你會有圖表。寫(「#chartdiv」);' – developius
在它的工作原理沒有#...它不會與#... – flori