frappe-charts多种图表效果及用法示例代码

代码语言:html

所属分类:图表

代码描述:frappe-charts多种图表效果及用法示例代码

代码标签: frappe-charts 图表 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/frappe_theme.css">
    <style>
    </style>

    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/highlight.9.9.js"></script>
    <script>
        hljs.initHighlightingOnLoad();
    </script>


</head>

<body>

    <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.storytellingwithdata.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="static/picture/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="//repo.bfw.wiki/bfwrepo/js/frappe-charts.min.js"&gt;&lt;/script&gt;</code></pre>

                    </div>
                </div>

            </div>
        </div>

    </div>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/frappe-charts.min.js"></script>
    <script>
        let reportCountList = [152, 222, 199, 287, 534, 709,
        	1179, 1256, 1632, 1856, 1850];
        
        let lineCompositeData = {
        	labels: ["2007", "2008", "2009", "2010", "2011", "2012",
        		"2013", "2014", "2015", "2016", "2017"],
        
        	yMarkers: [
        		{
        			label: "Average 100 reports/month",
        			value: 1200,
        		}
        	],
        
        	datasets: [{
        		"name": "Events",
        		"values": reportCountList
        	}]
        };
        
        
        let fireball_5_25 = [
        	[4, 0, 3, 1, 1, 2, 1, 1, 1, 0, 1, 1],
        	[2, 3, 3, 2, 1, 3, 0, 1, 2, 7, 10, 4],
        	[5, 6, 2, 4, 0, 1, 4, 3, 0, 2, 0, 1],
        	[0, 2, 6, 2, 1, 1, 2, 3, 6, 3, 7, 8],
        	[6, 8, 7, 7, 4, 5, 6, 5, 22, 12, 10, 11],
        	[7, 10, 11, 7, 3, 2, 7, 7, 11, 15, 22, 20],
        	[13, 16, 21, 18, 19, 17, 12, 17, 31, 28, 25, 29],
        	[24, 14, 21, 14, 11, 15, 19, 21, 41, 22, 32, 18],
        	[31, 20, 30, 22, 14, 17, 21, 35, 27, 50, 117, 24],
        	[32, 24, 21, 27, 11, 27, 43, 37, 44, 40, 48, 32],
        	[31, 38, 36, 26, 23, 23, 25, 29, 26, 47, 61, 50],
        ];
        let fireball_2_5 = [
        	[22, 6, 6, 9, 7, 8, 6, 14, 19, 10, 8, 20],
        	[11, 13, 12, 8, 9, 11, 9, 13, 10, 22, 40, 24],
        	[20, 13, 13, 19, 13, 10, 14, 13, 20, 18, 5, 9],
        	[7, 13, 16, 19, 12, 11, 21, 27, 27, 24, 33, 33],
        	[38, 25, 28, 22, 31, 21, 35, 42, 37, 32, 46, 53],
        	[50, 33, 36, 34, 35, 28, 27, 52, 58, 59, 75, 69],
        	[54, 67, 67, 45, 66, 51, 38, 64, 90, 113, 116, 87],
        	[84, 52, 56, 51, 55, 46, 50, 87, 114, 83, 152, 93],
        	[73, 58, 59, 63, 56, 51, 83, 140, 103, 115, 265, 89],
        	[106, 95, 94, 71, 77, 75, 99, 136, 129, 154, 168, 156],
        	[81, 102, 95, 72, 58, 91, 89, 122, 124, 135, 183, 171],
        ];
        let fireballOver25 = [
        	// [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        	[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
        	[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
        	[1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
        	[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2],
        	[3, 2, 1, 3, 2, 0, 2, 2, 2, 3, 0, 1],
        	[2, 3, 5, 2, 1, 3, 0, 2, 3, 5, 1, 4],
        	[7, 4, 6, 1, 9, 2, 2, 2, 20, 9, 4, 9],
        	[5, 6, 1, 2, 5, 4, 5, 5, 16, 9, 14, 9],
        	[5, 4, 7, 5, 1, 5, 3, 3, 5, 7, 22, 2],
        	[5, 13, 11, 6, 1, 7, 9, 8, 14, 17, 16, 3],
        	[8, 9, 8, 6, 4, 8, 5, 6, 14, 11, 21, 12]
        ];
      .........完整代码请登录后点击上方下载按钮下载查看

网友评论0