利用js实现Frappe Charts折线图表插件



7 26 9



特效描述:利用js实现 Frappe Charts 折线图表插件,利用js实现 Frappe Charts折线图表插件

代码结构

1. 引入CSS

<link rel="stylesheet" type="text/css" href="docs/assets/css/normalize.css" media="screen">
<link rel="stylesheet" type="text/css" href="docs/assets/css/bootstrap.min.css" media="screen">
<link rel="stylesheet" type="text/css" href="docs/assets/css/frappe_theme.css" media="screen">
<link rel="stylesheet" type="text/css" href="docs/assets/css/index.css" media="screen">
<link rel="stylesheet" type="text/css" href="docs/assets/css/default.css" media="screen">

2. 引入JS

<script src="docs/assets/js/highlight.pack.js"></script>
<script async defer src="dist/buttons.js"></script>
<script src="docs/assets/js/frappe-charts.min.js"></script>
<script src="docs/assets/js/index.js"></script>

3. HTML代码

<div class="container">
  <div class="row hero" style="padding-top: 30px; padding-bottom: 0px;">
	<div class="jumbotron" style="background: transparent;">
	  <h1>Frappe Charts</h1>
	  <p class="mt-2">GitHub-inspired simple and modern charts for the web</p>
	  <p class="mt-2">with zero dependencies.</p>
	  <!--<p class="mt-2">Because dumb charts are hard to come by.</p>-->
	</div>
	<div class="col-sm-10 push-sm-1 later" style="font-size: 14px;">
	  <div id="chart-composite-1" class="border"><svg height=225></svg></div>
	  <p class="mt-1">Click or use arrow keys to navigate data points</p>
	</div>
	<div class="col-sm-10 push-sm-1 later" style="font-size: 14px;">
	  <div id="chart-composite-2" class="border"><svg height=225></svg></div>
	</div>
  </div>
  <div class="group later">
	<div class="row section">
	  <div class="col-sm-10 push-sm-1">
		<div class="dashboard-section">
		  <h6 class="margin-vertical-rem">Create a chart</h6>
		  <pre><code class="hljs html">  &lt!--HTML--&gt;
&lt;div id="chart"&gt;&lt;/div&gt;</code></pre>
		  <pre><code class="hljs javascript">  // Javascript
let chart = new Chart( "#chart", { // or DOM element
data: {
  labels: ["12am-3am", "3am-6am", "6am-9am", "9am-12pm",
  "12pm-3pm", "3pm-6pm", "6pm-9pm", "9pm-12am"],
  datasets: [
	{
	  label: "Some Data", type: 'bar',
	  values: [25, 40, 30, 35, 8, 52, 17, -4]
	},
	{
	  label: "Another Set", type: 'bar',
	  values: [25, 50, -10, 15, 18, 32, 27, 14]
	},
	{
	  label: "Yet Another", type: 'line',
	  values: [15, 20, -3, -15, 58, 12, -17, 37]
	}
  ],
  yMarkers: [{ label: "Marker", value: 70 }],
  yRegions: [{ label: "Region", start: -10, end: 50 }]
},
title: "My Awesome Chart",
type: 'axis-mixed', // or 'bar', 'line', 'pie', 'percentage'
height: 250,
colors: ['purple', '#ffa3ef', 'red']
});</code></pre>
		  <!-- <div id="chart-types" class="border" style="margin-bottom: 15px"></div> -->
		  <!-- <div >
			<div class="btn-group x-axis-buttons margin-vertical-px" role="group">
			  <button type="button" class="btn btn-sm btn-secondary active" data-type='span'>X span</button>
			  <button type="button" class="btn btn-sm btn-secondary" data-type='tick'>X tick</button>
			</div>
			<div class="btn-group y-axis-buttons margin-vertical-px" role="group">
			  <button type="button" class="btn btn-sm btn-secondary active" data-type='span'>Y span</button>
			  <button type="button" class="btn btn-sm btn-secondary" data-type='tick'>Y tick</button>
			</div>
			<div class="input-group input-group-sm">
			  <span class="input-group-addon">.00</span>
			  <input type="text" class="form-control" aria-label="Amount (rounded to the nearest dollar)">
			</div>
		  </div> -->
		  <div id="chart-aggr" class="border"></div>
		  <div class="btn-group aggr-type-buttons margin-vertical-px mx-auto" role="group">
			<button type="button" class="btn btn-sm btn-secondary active" data-type='axis-mixed'>Mixed</button>
			<button type="button" class="btn btn-sm btn-secondary" data-type='pie'>Pie Chart</button>
			<button type="button" class="btn btn-sm btn-secondary" data-type='percentage'>Percentage Chart</button>
		  </div>
		  <!-- <p class="text-muted">
			<a target="_blank" href="http://www.51qianduan.com//blog/2011/07/death-to-pie-charts">Why Percentage?</a>
		  </p> -->
		</div>
	  </div>
	  <div class="col-sm-10 push-sm-1">
		<div class="dashboard-section">
		  <h6 class="margin-vertical-rem">
			Update Values
		  </h6>
		  <div id="chart-update" class="border"></div>
		  <div class="chart-update-buttons mt-1 mx-auto" role="group">
			<button type="button" class="btn btn-sm btn-secondary" data-update="random">Random Data</button>
			<button type="button" class="btn btn-sm btn-secondary" data-update="add">Add Value</button>
			<button type="button" class="btn btn-sm btn-secondary" data-update="remove">Remove Value</button>
		  </div>
		</div>
	  </div>
	  <div class="col-sm-10 push-sm-1">
		<div class="dashboard-section">
		  <h6 class="margin-vertical-rem">
			Plot Trends
		  </h6>
		  <div id="chart-trends" class="border"></div>
		  <div class="btn-group chart-plot-buttons mt-1 mx-auto" role="group">
			<button type="button" class="btn btn-sm btn-secondary" data-type="hideDots">Line</button>
			<button type="button" class="btn btn-sm btn-secondary" data-type="hideLine">Dots</button>
			<button type="button" class="btn btn-sm btn-secondary active" data-type="heatline">HeatLine</button>
			<button type="button" class="btn btn-sm btn-secondary" data-type="regionFill">Region</button>
		  </div>
		  <!-- <pre><code class="hljs javascript margin-vertical-px">  ...
lineOptions: 'line',   // Line Chart specific properties:
hideDots: 1,   // Hide data points on the line; default 0
heatline: 1,    // Show a value-wise line gradient; default 0
regionFill: 1, // Fill the area under the graph; default 0
...</code></pre> -->
		</div>
	  </div>
	  <div class="col-sm-10 push-sm-1">
		<div class="dashboard-section">
		  <h6 class="margin-vertical-rem">
			Listen to state change
		  </h6>
		  <div class="row">
			<div class="col-sm-8">
			  <div id="chart-events" class="border"></div>
			</div>
			<div class="col-sm-4">
			  <div class="chart-events-data" class="border data-container">
				<div class="image-container border">
				  <img class="moon-image" src="docs/assets/img/europa.jpg">
				</div>
				<div class="data margin-vertical-px">
				  <h6 class="moon-name">Europa</h6>
				  <p>Semi-major-axis: <span class="semi-major-axis">671034</span> km</p>
				  <p>Mass: <span class="mass">4800000</span>  x 10^16 kg</p>
				  <p>Diameter: <span class="diameter">3121.6</span> km</p>
				</div>
			  </div>
			</div>
		  </div>
		  <pre><code class="hljs javascript margin-vertical-px">  ...
isNavigable: 1, // Navigate across data points; default 0
...
chart.parent.addEventListener('data-select', (e) => {
update_moon_data(e.index); // e contains index and value of current datapoint
});</code></pre>
		</div>
	  </div>
	  <div class="col-sm-10 push-sm-1">
		<div class="dashboard-section">
		  <h6 class="margin-vertical-rem">
			And a Month-wise Heatmap
		  </h6>
		  <div id="chart-heatmap" class="border"
			style="overflow: scroll; text-align: center; padding: 20px;"></div>
		  <div class="heatmap-mode-buttons btn-group mt-1 mx-auto" role="group">
			<button type="button" class="btn btn-sm btn-secondary active" data-mode="discrete">Discrete</button>
			<button type="button" class="btn btn-sm btn-secondary" data-mode="continuous">Continuous</button>
		  </div>
		  <div class="heatmap-color-buttons btn-group mt-1 mx-auto" role="group">
			<button type="button" class="btn btn-sm btn-secondary" data-color="default">Default green</button>
			<button type="button" class="btn btn-sm btn-secondary active" data-color="halloween">GitHub's Halloween</button>
		  </div>
		  <pre><code class="hljs javascript margin-vertical-px">  let heatmap = new Chart("#heatmap", {
type: 'heatmap',
height: 115,
data: heatmapData,  // object with date/timestamp-value pairs
discreteDomains: 1  // default: 0
start: startDate,
			  // A Date object;
			  // default: today's date in past year
			  //          for an annual heatmap
legendColors: ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001c'],
			  // Set of five incremental colors,
			  // beginning with a low-saturation color for zero data;
			  // default: ['#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127']
});</code></pre>
		</div>
	  </div>
	  <div class="col-sm-10 push-sm-1">
		  <div class="dashboard-section">
			<h6 class="margin-vertical-rem">Available options:</h6>
			<pre><code class="hljs javascript">
...
{
data: {
  labels: [],
  datasets: [],
  yRegions: [],
  yMarkers: []
}
title: '',
colors: [],
height: 200,
tooltipOptions: {
  formatTooltipX: d => (d + '').toUpperCase(),
  formatTooltipY: d => d + ' pts',
}
// Axis charts
isNavigable: 1,        // default: 0
valuesOverPoints: 1,   // default: 0
barOptions: {
  stacked: 1           // default: 0
}
lineOptions: {
  dotSize: 6,          // default: 4
  hideLine: 0,         // default: 0
  hideDots: 1,         // default: 0
  heatline: 1,         // default: 0
  regionFill: 1        // default: 0
}
axisOptions: {
  yAxisMode: 'span',   // Axis lines, default
  xAxisMode: 'tick',   // No axis lines, only short ticks
  xIsSeries: 1         // Allow skipping x values for space
					   // default: 0
},
// Pie/Percentage charts
maxLegendPoints: 6,    // default: 20
maxSlices: 10,         // default: 20
// Heatmap
discreteDomains: 1,    // default: 1
start: startDate,      // Date object
legendColors: []
}
...
// Updating values
chart.update(data);
// Axis charts:
chart.addDataPoint(label, valueFromEachDataset, index)
chart.removeDataPoint(index)
chart.updateDataset(datasetValues, index)
</code></pre>
		  </div>
		</div>
	  <div class="col-sm-10 push-sm-1">
		<div class="dashboard-section">
		  <h6 class="margin-vertical-rem">Install</h6>
		  <p class="step-explain">Install via npm</p>
		  <pre><code class="hljs console">  npm install frappe-charts</code></pre>
		  <p class="step-explain">And include it in your project</p>
		  <pre><code class="hljs javascript">  import Chart from "frappe-charts/dist/frappe-charts.min.esm"</code></pre>
		  <p class="step-explain">... or include it directly in your HTML</p>
		  <pre><code class="hljs html">  &lt;script src="https://unpkg.com/frappe-charts@1.0.0/dist/frappe-charts.min.iife.js"&gt;&lt;/script&gt;</code></pre>
		</div>
	  </div>
	</div>
  </div>
</div>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 弹出层拖动 窗口 弹出 弹窗 弹出层 提示框 对话框 遮罩 遮罩层 弹窗插件 滑动星星打分 其他 文字提示框 提示文字 图表

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到