GVKun编程网logo

javascript – Chartist.js – 增加Y轴刻度点之间的间距

15

在这篇文章中,我们将带领您了解javascript–Chartist.js–增加Y轴刻度点之间的间距的全貌,同时,我们还将为您介绍有关ActiveX控件与Javascript之间的交互示例_javas

在这篇文章中,我们将带领您了解javascript – Chartist.js – 增加Y轴刻度点之间的间距的全貌,同时,我们还将为您介绍有关ActiveX控件与Javascript之间的交互示例_javascript技巧、application/x-javascript 和 text/javascript 内容类型之间的区别、echarts 修改y轴刻度间隔问题、echarts 平均值及 y轴刻度n等分配置的知识,以帮助您更好地理解这个主题。

本文目录一览:

javascript – Chartist.js – 增加Y轴刻度点之间的间距

javascript – Chartist.js – 增加Y轴刻度点之间的间距

我正在制作一个个人项目,创建图表,以显示有关Last FM API的音乐收听习惯的数据.

我通过AJAX请求获取JSON数据,然后使用返回的JSON对象填充使用Chartist.js JS库创建的图形.

我有一个我认为是一个非常简单的问题,因为我无法弄清楚如何增加图表的整体大小?更具体地说,我想增加Y轴上每个刻度点之间的间距,以便您可以更准确地看到每个图形.

我创建了以下JS fiddle来显示我的问题:

http://jsfiddle.net/jt96usn9/

根据文档,我认为我需要更改一个名为scaleMinSpace的选项属性,但在更改此数字后,似乎不会发生任何更改.

任何帮助都会很棒?!

var lastfm = {};

lastfm.tracker = (function(){

	//Set up an object for DOM elements and data source
	var config = {
		getRecentTracksURL: "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=jimmersjukeBox&api_key=6db1989bd348bf91797bad802c6645d8&format=json",getMostPopularartistsURL: "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=jimmersjukeBox&api_key=6db1989bd348bf91797bad802c6645d8&format=json",user: "jimmersjukeBox",recentTracksElement: $(".recent-tracks"),currentlyPlayingActiveClass: $(".current")
	};


	var setupLastFM = function(){
		createPopularartistsChart();
	};



	var createPopularartistsChart = function(){


		$.getJSON(config.getMostPopularartistsURL,function(data){
			var artistData = data.topartists.artist,artists = $.map(artistData,function(artist) {
				return [[artist.name]];
			}),playcounts = $.map(artistData,function(playcount) {
				return [[playcount.playcount]];
			});


			// These are the default options of the line chart
			var options = {
			  // Options for X-Axis
			  axisX: {
			    // The offset of the labels to the chart area
			    offset: 10,// If labels should be shown or not
			    showLabel: true,// If the axis grid should be drawn or not
			    showGrid: true,// Interpolation function that allows you to intercept the value from the axis label
			    labelInterpolationFnc: function(value){return value;}
			  },// Options for Y-Axis
			  axisY: {
			    scaleMinSpace: 100
			  },// Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
			  width: undefined,// Specify a fixed height for the chart as a string (i.e. '100px' or '50%')
			  height: undefined,// If the line should be drawn or not
			  showLine: true,// If dots should be drawn or not
			  showPoint: true,// Specify if the lines should be smoothed (Catmull-Rom-Splines will be used)
			  linesmooth: true,// Overriding the natural low of the chart allows you to zoom in or limit the charts lowest displayed value
			  low: undefined,// Overriding the natural high of the chart allows you to zoom in or limit the charts highest displayed value
			  high: undefined,// Padding of the chart drawing area to the container element and labels
			  chartPadding: 15,// Specify the distance in pixel of bars in a group
			  seriesBardistance: 15,// Override the class names that get used to generate the SVG structure of the chart

			};

			data = {
			  // A labels array that can contain any sort of values
			  labels: artists.slice(0,10),// Our series array that contains series objects or in this case series data arrays
			  series: [
			  	playcounts.slice(0,10)
			  ]
			};

			// Create a new line chart object where as first parameter we pass in a selector
			// that is resolving to our chart container element. The Second parameter
			// is the actual data object.
			Chartist.Bar('.ct-chart',data,options);

		});



	};

	return{
		config: config,init: function(){
			setupLastFM();
		}
	};
})();
$(window).load(lastfm.tracker.init);
/* Chartist.js 0.2.4
 * copyright © 2014 Gion Kunz
 * Free to use under the WTFPL license.
 * http://www.wtfpl.net/
 */

.ct-chart .ct-label{fill:rgba(0,.4);font-size:.75rem}.ct-chart .ct-grid{stroke:rgba(0,.2);stroke-width:1px;stroke-dasharray:2px}.ct-chart .ct-point{stroke-width:10px;stroke-linecap:round}.ct-chart .ct-line{fill:none;stroke-width:4px}.ct-chart .ct-area{stroke:none;fill-opacity:.1}.ct-chart .ct-bar{fill:none;stroke-width:10px}.ct-chart .ct-slice.ct-donut{fill:none;stroke-width:60px}.ct-chart .ct-series.ct-series-a .ct-bar,.ct-chart .ct-series.ct-series-a .ct-line,.ct-chart .ct-series.ct-series-a .ct-point,.ct-chart .ct-series.ct-series-a .ct-slice.ct-donut{stroke:#d70206}.ct-chart .ct-series.ct-series-a .ct-area,.ct-chart .ct-series.ct-series-a .ct-slice:not(.ct-donut){fill:#d70206}.ct-chart .ct-series.ct-series-b .ct-bar,.ct-chart .ct-series.ct-series-b .ct-line,.ct-chart .ct-series.ct-series-b .ct-point,.ct-chart .ct-series.ct-series-b .ct-slice.ct-donut{stroke:#F05B4F}.ct-chart .ct-series.ct-series-b .ct-area,.ct-chart .ct-series.ct-series-b .ct-slice:not(.ct-donut){fill:#F05B4F}.ct-chart .ct-series.ct-series-c .ct-bar,.ct-chart .ct-series.ct-series-c .ct-line,.ct-chart .ct-series.ct-series-c .ct-point,.ct-chart .ct-series.ct-series-c .ct-slice.ct-donut{stroke:#F4C63D}.ct-chart .ct-series.ct-series-c .ct-area,.ct-chart .ct-series.ct-series-c .ct-slice:not(.ct-donut){fill:#F4C63D}.ct-chart .ct-series.ct-series-d .ct-bar,.ct-chart .ct-series.ct-series-d .ct-line,.ct-chart .ct-series.ct-series-d .ct-point,.ct-chart .ct-series.ct-series-d .ct-slice.ct-donut{stroke:#453D3F}.ct-chart .ct-series.ct-series-d .ct-area,.ct-chart .ct-series.ct-series-d .ct-slice:not(.ct-donut){fill:#453D3F}.ct-chart.ct-square{display:block;position:relative;width:100%}.ct-chart.ct-square:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:100%}.ct-chart.ct-square:after{content:"";display:table;clear:both}.ct-chart.ct-square>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-minor-second{display:block;position:relative;width:100%}.ct-chart.ct-minor-second:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:93.75%}.ct-chart.ct-minor-second:after{content:"";display:table;clear:both}.ct-chart.ct-minor-second>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-major-second{display:block;position:relative;width:100%}.ct-chart.ct-major-second:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:88.8888888889%}.ct-chart.ct-major-second:after{content:"";display:table;clear:both}.ct-chart.ct-major-second>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-minor-third{display:block;position:relative;width:100%}.ct-chart.ct-minor-third:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:83.3333333333%}.ct-chart.ct-minor-third:after{content:"";display:table;clear:both}.ct-chart.ct-minor-third>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-major-third{display:block;position:relative;width:100%}.ct-chart.ct-major-third:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:80%}.ct-chart.ct-major-third:after{content:"";display:table;clear:both}.ct-chart.ct-major-third>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-perfect-fourth{display:block;position:relative;width:100%}.ct-chart.ct-perfect-fourth:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:75%}.ct-chart.ct-perfect-fourth:after{content:"";display:table;clear:both}.ct-chart.ct-perfect-fourth>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-perfect-fifth{display:block;position:relative;width:100%}.ct-chart.ct-perfect-fifth:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:66.6666666667%}.ct-chart.ct-perfect-fifth:after{content:"";display:table;clear:both}.ct-chart.ct-perfect-fifth>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-minor-sixth{display:block;position:relative;width:100%}.ct-chart.ct-minor-sixth:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:62.5%}.ct-chart.ct-minor-sixth:after{content:"";display:table;clear:both}.ct-chart.ct-minor-sixth>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-golden-section{display:block;position:relative;width:100%}.ct-chart.ct-golden-section:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:61.804697157%}.ct-chart.ct-golden-section:after{content:"";display:table;clear:both}.ct-chart.ct-golden-section>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-major-sixth{display:block;position:relative;width:100%}.ct-chart.ct-major-sixth:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:60%}.ct-chart.ct-major-sixth:after{content:"";display:table;clear:both}.ct-chart.ct-major-sixth>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-minor-seventh{display:block;position:relative;width:100%}.ct-chart.ct-minor-seventh:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:56.25%}.ct-chart.ct-minor-seventh:after{content:"";display:table;clear:both}.ct-chart.ct-minor-seventh>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-major-seventh{display:block;position:relative;width:100%}.ct-chart.ct-major-seventh:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:53.3333333333%}.ct-chart.ct-major-seventh:after{content:"";display:table;clear:both}.ct-chart.ct-major-seventh>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-octave{display:block;position:relative;width:100%}.ct-chart.ct-octave:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:50%}.ct-chart.ct-octave:after{content:"";display:table;clear:both}.ct-chart.ct-octave>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-major-tenth{display:block;position:relative;width:100%}.ct-chart.ct-major-tenth:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:40%}.ct-chart.ct-major-tenth:after{content:"";display:table;clear:both}.ct-chart.ct-major-tenth>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-major-eleventh{display:block;position:relative;width:100%}.ct-chart.ct-major-eleventh:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:37.5%}.ct-chart.ct-major-eleventh:after{content:"";display:table;clear:both}.ct-chart.ct-major-eleventh>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-major-twelfth{display:block;position:relative;width:100%}.ct-chart.ct-major-twelfth:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:33.3333333333%}.ct-chart.ct-major-twelfth:after{content:"";display:table;clear:both}.ct-chart.ct-major-twelfth>svg{display:block;position:absolute;top:0;left:0}.ct-chart.ct-double-octave{display:block;position:relative;width:100%}.ct-chart.ct-double-octave:before{display:block;float:left;content:"";width:0;height:0;padding-bottom:25%}.ct-chart.ct-double-octave:after{content:"";display:table;clear:both}.ct-chart.ct-double-octave>svg{display:block;position:absolute;top:0;left:0}
<script src="//cdnjs.cloudflare.com/ajax/libs/chartist/0.2.4/chartist.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div>
                <div></div>
            </div>

解决方法

如果你在选项中给出高度

var options = {
                    seriesBardistance: 10,fullWidth: true,showArea:true,height:'500px'

            };
new Chartist.Bar('.ct-chart',dataArray,options,responsiveOptions );

它也会增加整体高度和间距.谢谢基兰.

ActiveX控件与Javascript之间的交互示例_javascript技巧

ActiveX控件与Javascript之间的交互示例_javascript技巧

1、ActiveX向Javascript传参

复制代码 代码如下:



objectname为ActiveX控件名,通过标签里的id属性设定,如下;
复制代码 代码如下:

name="objectname"
codebase="objectname.cab#version=1,0,0,0"
classid="clsid:357A8DEC-0CFC-4D8D-9869-C2C356B844F7">


fun1(arg)为ActiveX控件的函数,这里作为事件,当ActiveX控件里的fun1运行后,Javascript的事件被触发,fun2被调用,arg为ActiveX控件传来的参数。
待添加……

application/x-javascript 和 text/javascript 内容类型之间的区别

application/x-javascript 和 text/javascript 内容类型之间的区别

这些标题之间有什么区别?

Content-Type: application/javascriptContent-Type: application/x-javascriptContent-Type: text/javascript

哪一个是最好的,为什么?

请不要说它们是相同的——如果它们相同,就不会有三个。我知道两者都有效-但我想知道区别。

答案1

小编典典

text/javascript已经过时,并且在过渡时期application/x-javascript是实验性的(因此是前缀),直到可以标准化。x-``application/javascript

你应该使用application/javascript. 这记录在RFC中。

就浏览器而言,没有区别(至少在 HTTP 标头中)。这只是一个更改,以便text/*application/*MIME
类型组在可能的情况下具有一致的含义。(text/*MIME 类型旨在用于人类可读的内容,JavaScript 并非旨在直接向人类传达意义)。

请注意,application/javascript在脚本元素的type属性中使用会导致脚本在某些较旧的浏览器中被忽略(因为使用未知语言)。要么继续使用text/javascript,要么完全省略该属性(这在
HTML 5 中是允许的)。

这在 HTTP 标头中不是问题,因为浏览器普遍(据我所知)要么完全忽略脚本的 HTTP
内容类型,要么足够现代以识别application/javascript.

echarts 修改y轴刻度间隔问题

echarts 修改y轴刻度间隔问题

其中min、max可以自定义可以动态获取数据

yAxis : [

                    {
                        type : ''value'',
                        axisLine:{show:true,
                        lineStyle:{color:''#ccc''}
                        },
                        axisTick:{
                        show:false,                         
                        },
                        axisLabel:{
                        show:true,
                        inside:true
                        },
                        min:min,
                        max:max,
                        splitNumber:8
                         
                    }
                ],

echarts 平均值及 y轴刻度n等分配置

echarts 平均值及 y轴刻度n等分配置

// 平均值
markLine: {
      symbol: ''none'',
      silent: true,
      label: {
      show: true,    
      normal: {
          formatter: ''平均ROI: {c}'',
       },       
       position: ''end'',
    },
    data: [  
     {
      type: ''average'',  // type 类型, 可以是最大值max, 最小值min, 平均值
      name: ''平均值'',
     },
    ],
}

// 坐标轴刻度 n 等分
interval: maxValue / 5,  // maxValue为你计算出来的值, 即数组中的最大值

// 区域缩放 
dataZoom: [
      {
        show: true,
        start: 0,     //  初始化展示个数  开始百分比
        end: 10,    // 初始化展示个数  结束百分比 10 表示展示总数的10%
        zoomLock: true,  // 是否锁定选择区域(或叫做数据窗口)的大小。
        bottom: -13,  // 相对于容器高宽的位置
        backgroundColor: ''#2E4E88'',  // 缩放条背景色
        showDetail: false,   // 是否显示detail,即拖拽时候显示详细数值信息
      },
    ],

 

今天关于javascript – Chartist.js – 增加Y轴刻度点之间的间距的讲解已经结束,谢谢您的阅读,如果想了解更多关于ActiveX控件与Javascript之间的交互示例_javascript技巧、application/x-javascript 和 text/javascript 内容类型之间的区别、echarts 修改y轴刻度间隔问题、echarts 平均值及 y轴刻度n等分配置的相关知识,请在本站搜索。

本文标签:

上一篇javascript – 如何组合多个数组中的值以创建新的组合数组(多个数组合并成一个数组js)

下一篇javascript – 单元测试Angular Browserify Gulp和Jasmine(javascript unit test)