Вопрос

Я пытаюсь использовать FillText, чтобы нарисовать на Chart.js Canvas после его оказания, и он не будет работать.Лучшее, что я могу сделать, это изменить шрифт графика.Вот мой код.

var options = {

    //Boolean - If we show the scale above the chart data           
    scaleOverlay: false,

    //Boolean - If we want to override with a hard coded scale
    scaleOverride: false,

    //** Required if scaleOverride is true **
    //Number - The number of steps in a hard coded scale
    scaleSteps: null,
    //Number - The value jump in the hard coded scale
    scaleStepWidth: null,
    //Number - The scale starting value
    scaleStartValue: null,

    //String - Colour of the scale line 
    scaleLineColor: "rgba(0,0,0,.1)",

    //Number - Pixel width of the scale line    
    scaleLineWidth: 1,

    //Boolean - Whether to show labels on the scale 
    scaleShowLabels: true,

    //Interpolated JS string - can access value
    scaleLabel: "<%=value%>",

    //String - Scale label font declaration for the scale label
    scaleFontFamily: "'Arial'",

    //Number - Scale label font size in pixels  
    scaleFontSize: 12,

    //String - Scale label font weight style    
    scaleFontStyle: "normal",

    //String - Scale label font colour  
    scaleFontColor: "#666",

    ///Boolean - Whether grid lines are shown across the chart
    scaleShowGridLines: true,

    //String - Colour of the grid lines
    scaleGridLineColor: "rgba(0,0,0,.05)",

    //Number - Width of the grid lines
    scaleGridLineWidth: 1,

    //Boolean - Whether the line is curved between points
    bezierCurve: true,

    //Boolean - Whether to show a dot for each point
    pointDot: true,

    //Number - Radius of each point dot in pixels
    pointDotRadius: 3,

    //Number - Pixel width of point dot stroke
    pointDotStrokeWidth: 1,

    //Boolean - Whether to show a stroke for datasets
    datasetStroke: true,

    //Number - Pixel width of dataset stroke
    datasetStrokeWidth: 2,

    //Boolean - Whether to fill the dataset with a colour
    datasetFill: true,

    //Boolean - Whether to animate the chart
    animation: false,

    //Number - Number of animation steps
    animationSteps: 60,

    //String - Animation easing effect
    animationEasing: "easeOutQuart",

    //Function - Fires when the animation is complete
    onAnimationComplete: null

}
.

Диаграмма Данные этикетки и точки - это массивы.

                   var chartData = {
                        labels: labels,
                        datasets: [
                            {
                                fillColor: "rgba(220,220,220,0.5)",
                                strokeColor: "rgba(220,220,220,1)",
                                pointColor: "rgba(220,220,220,1)",
                                pointStrokeColor: "#fff",
                                data: points
                            }
                        ]
                    }

                    var ctx = $("#" + item.logon).get(0).getContext("2d");
                    var chart = new Chart(ctx).Line(chartData, options);
.

Это делается с данными JSON и после звонка у меня есть:

                $("canvas").each(function (i, item) {
                    var context = $(this).get(0).getContext("2d");
                    context.textBaseline = 'top';
                    context.fillText('Test', 0, 0);
                });
.

Графики просто загружаются нормально без какого-либо текста.Если я использую контекст. Тогда все метки на каждом холсте изменены.Я выключил загрузку анимации.Любые идеи?

Это было полезно?

Решение

вместо того, чтобы рисовать на холсте, я просто добавляю этикетку вокруг элемента

<label for = "idOfCanvas">
Your Label<br />
    <canvas></canvas>
</label>
.

Другие советы

в параметре добавить этот параметр

    multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>"
.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top