Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chart.js以定义的值开始Y轴_Javascript_Php_Chart.js - Fatal编程技术网

Javascript Chart.js以定义的值开始Y轴

Javascript Chart.js以定义的值开始Y轴,javascript,php,chart.js,Javascript,Php,Chart.js,我在网站上使用的插件使用Chart.js 我尝试以定义的值开始Y轴 这是我现在拥有的一张照片: 折线图 javascript代码: (function() { Chart.types.Line.extend({ name:'UncontinuousLine', defaults:{scaleBeginAtZero:false}, initialize:function(data) { Chart.types.Line.prototype.initiali

我在网站上使用的插件使用Chart.js 我尝试以定义的值开始Y轴

这是我现在拥有的一张照片: 折线图

javascript代码:

(function() {
Chart.types.Line.extend({
    name:'UncontinuousLine',
    defaults:{scaleBeginAtZero:false},
    initialize:function(data) {
        Chart.types.Line.prototype.initialize.apply(this,arguments);
    },
    draw:function() {
        Chart.types.Line.prototype.draw.apply(this,arguments);
        var ctx=this.chart.ctx;
        this.datasets.forEach(function(ds) {
            ctx.strokeStyle=ds.strokeColor;
            var prevPt={value:2.49};
            ds.points.forEach(function(curPt) {
                if(parseInt(curPt.value)<=0) {
                    curPt.value=prevPt.value;
                } 
                if(parseInt(curPt.value)>0&&parseInt(prevPt.value)>0) {
                    ctx.beginPath();
                    ctx.moveTo(prevPt.x,prevPt.y);
                    ctx.lineTo(curPt.x,curPt.y);
                    ctx.stroke();
                } 
                prevPt=curPt;
            });
        });

    }
});})(); 
(函数(){
Chart.types.Line.extend({
名称:'UncontinuousLine',
默认值:{scaleBeginAtZero:false},
初始化:函数(数据){
Chart.types.Line.prototype.initialize.apply(这是参数);
},
绘图:函数(){
Chart.types.Line.prototype.draw.apply(这是参数);
var ctx=this.chart.ctx;
this.datasets.forEach(函数(ds){
ctx.strokeStyle=ds.strokeColor;
var-prevPt={value:2.49};
ds.points.forEach(函数(curPt){
if(parseInt(curPt.value)0&&parseInt(prevPt.value)>0){
ctx.beginPath();
ctx.moveTo(上一页x,上一页y);
ctx.lineTo(电流x、电流y);
ctx.stroke();
} 
prevPt=curPt;
});
});
}
});})(); 
以及php代码:

private function _create_uncontinuousline_chart( $data, $opt ){ 
    if ( empty( $data ) ){ 
        return '';
    } 
    $id = self::_get_canvas_id( $this->count );
    $sets = self::_parse_data( $data, 3 );
    $cd = self::_resort_sets( $sets, true );
    $this->js[] = 'new Chart(' . "jQuery('#$id').get(0).getContext('2d')" . ')
                    .UncontinuousLine(' . AimyChartsContentPluginHelper::phpva_json_encode( $cd ) . ',' 
                    . '{' . 'animation: ' . ( $opt[ 'animate' ] ? 'true' : 'false' ) . ',' 
                    . 'multiTooltipTemplate: ' . '"<%= value %> (<%= datasetLabel %>)"' 
                    . ',responsive: ' . ( $opt[ 'responsive' ] ? 'true' : 'false' ) 
                    . ',datasetStrokeWidth:0.01' . '}' . ');';
    return self::_get_canvas( 'UncontinuousLine', $this->count, $opt );
}
private函数\u创建\u不连续的直线图($data,$opt){
if(空($data)){
返回“”;
} 
$id=self::_get_canvas_id($this->count);
$sets=self::_parse_data($data,3);
$cd=self::_resort_set($set,true);
$this->js[]='new Chart('.'jQuery('#$id')。get(0)。getContext('2d')。)
.UncontinuousLine('.AimyChartsContentPluginHelper::phpva_json_encode($cd)。'
“{.”动画:“($opt['animate']?'true':'false'),”
“多工具模板:”。“()”'
“,响应:”。($opt['responsive']?'true':'false')
,datasetStrokeWidth:0.01'.}.);
返回self::_get_canvas('UncontinuousLine',$this->count,$opt);
}
我尝试过很多方法,但不可能在1开始我的y轴,例如。。。
有人知道我怎么做吗?

在您的选项中,使用以下选项:

 scaleBeginAtZero : false,
 scaleOverride: true,
 scaleStartValue: 1,
为您的php代码尝试以下方法:

private function _create_uncontinuousline_chart( $data, $opt ){ 
    if ( empty( $data ) ){ 
        return '';
    } 
    $id = self::_get_canvas_id( $this->count );
    $sets = self::_parse_data( $data, 3 );
    $cd = self::_resort_sets( $sets, true );
    $this->js[] = 'new Chart(' . "jQuery('#$id').get(0).getContext('2d')" . ')
                    .UncontinuousLine(' . AimyChartsContentPluginHelper::phpva_json_encode( $cd ) . ',' 
                    . '{' . 'animation: ' . ( $opt[ 'animate' ] ? 'true' : 'false' )  
                    . ',multiTooltipTemplate: ' . '"<%= value %> (<%= datasetLabel %>)"' 
                    . ',responsive: ' . ( $opt[ 'responsive' ] ? 'true' : 'false' ) 
                    . ',datasetStrokeWidth:0.01' 
                    . ',scaleBeginAtZero : false'
                    . ',scaleOverride: true'
                    . ',scaleStartValue: 1'
                    . '}' . ');';
    return self::_get_canvas( 'UncontinuousLine', $this->count, $opt );
private函数\u创建\u不连续的直线图($data,$opt){
if(空($data)){
返回“”;
} 
$id=self::_get_canvas_id($this->count);
$sets=self::_parse_data($data,3);
$cd=self::_resort_set($set,true);
$this->js[]='new Chart('.'jQuery('#$id')。get(0)。getContext('2d')。)
.UncontinuousLine('.AimyChartsContentPluginHelper::phpva_json_encode($cd)。'
“{.”动画:。($opt['animate']?'true':'false')
“,”多工具模板:'.“()”'
“,响应:”。($opt['responsive']?'true':'false')
,datasetStrokeWidth:0.01'
“,scaleBeginAtZero:false”
“,scaleOverride:正确”
“,scaleStartValue:1”
. '}' . ');';
返回self::_get_canvas('UncontinuousLine',$this->count,$opt);

查看选项scaleOverride、scaleSteps、scaleStepWidth和scaleStartValueHello,谢谢你的回复。我已经尝试过了,但不是在正确的地方做了,就是不起作用嘿,谢谢你的帮助。我使用extend是因为有时会有空值,所以我想在这种情况下剪切图形,但经过反射后,恢复p前面的值更有趣。我曾尝试在我的选项中添加此值,但不起作用(我将其放在我的php中,'datasetStrokeWidth:0.01'之后,是否有?)更新了我的答案,添加了一段php代码片段,我认为这段代码可以与当前的设置一起使用。您有可以公开查看的地方吗?也许可以将其放在jsfiddle.net上?您好,我以前也尝试过,但如果我这样做,图表就会消失(cf:)。另一方面,这些值会出现在悬停时显示的窗口中。我现在不知道如何将其放在jsfiddle.net上,因为它可以与joomla插件一起工作。无论如何,谢谢。如果这些值出现在工具提示中,那么我们就有了正确的数据,如果我能看到输出(图表),那么它的配置就有了一些东西然后我可以看到那边有什么问题,并找出解决办法。我有一个url吗?嘿,我的网站目前是本地的。数据是正确的,但正如我们在最后一个屏幕截图上看到的,y轴从0开始。唯一的区别是不再出现线条。我相信这将保持不变。如果运气好的话,一个是d是的,这将由插件的创建者提出。感谢您所花的时间!