[英]How to make jqPlot work with the bar chart example
I am trying to run an example from jqPlot
.我正在尝试从jqPlot
运行一个示例。 I adapted their code to my page:我将他们的代码调整到我的页面:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Tests</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<div>Testing a chart 2</div>
<script type="text/javascript" src="jqplot.barRenderer.min.js"></script>
<script type="text/javascript" src="jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript" src="jqplot.pointLabels.min.js"></script>
<script language=javascript type="text/javascript">
$(document).ready(function() {
var s1 = [200, 600, 700, 1000];
var s2 = [460, -210, 690, 820];
var s3 = [-260, -440, 320, 200];
// Can specify a custom tick Array.
// Ticks should match up one for each y value (category) in the series.
var ticks = ['May', 'June', 'July', 'August'];
var plot1 = $.jqplot('chart1', [s1, s2, s3], {
// The "seriesDefaults" option is an options object that will
// be applied to all series in the chart.
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: {fillToZero: true}
},
// Custom labels for the series are specified with the "label"
// option on the series option. Here a series option object
// is specified for each series.
series: [
{label: 'Hotel'},
{label: 'Event Regristration'},
{label: 'Airfare'}
],
// Show the legend and put it outside the grid, but inside the
// plot container, shrinking the grid to accomodate the legend.
// A value of "outside" would not shrink the grid and allow
// the legend to overflow the container.
legend: {
show: true,
placement: 'outsideGrid'
},
axes: {
// Use a category axis on the x axis and use our custom ticks.
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
},
// Pad the y axis just a little so bars can get close to, but
// not touch, the grid boundaries. 1.2 is the default padding.
yaxis: {
pad: 1.05,
tickOptions: {formatString: '$%d'}
}
}
});
});
</script>
<div id="chart1" style="height:400px;width:300px; "></div>
<br><a href="/Test/index.html">Home</a>
</body>
</html>
Note that I created the div
with the chart name chart1
, then plugins were added accordingly.请注意,我使用图表名称chart1
创建了div
,然后相应地添加了插件。
You need to add the main "jqplot" javascript file and not only the plugin files :您需要添加主要的“jqplot”javascript 文件,而不仅仅是插件文件:
<script type="text/javascript" src="jquery.jqplot.js"></script>
Please see working example here请在此处查看工作示例
PS : about your Chart2.html file (in your archive) PS :关于你的 Chart2.html 文件(在你的档案中)
Thus the correct javascript and css inclusion is :因此,正确的 javascript 和 css 包含是:
<script src="jquery.min.js"></script>
<script src="jquery.jqplot.min.js"></script>
<script src="jqplot.barRenderer.min.js"></script>
<script src="jqplot.categoryAxisRenderer.min.js"></script>
<script src="jqplot.pointLabels.min.js"></script>
<link href="jquery.jqplot.css" rel="stylesheet" type="text/css">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.