score:24
you can try one thing
try to separate the legend into an different div. now you have full control of the div you can use custom placement and css of your own consider the following code :
<div id="js-legend" class="chart-legend"></div>
document.getelementbyid('js-legend').innerhtml = mychart.generatelegend();
for reference see this fiddle
for handling legend interactive you need to extend the callback function and manipulate like this :
$("#js-legend > ul > li").on("click",function(e){
var index = $(this).index();
$(this).toggleclass("strike")
var ci = e.view.mychart;
var curr = ci.data.datasets[0]._meta[0].data[index];
curr.hidden = !curr.hidden
ci.update();
})
for legend in action see this fiddle
explanation :
i binded chart to window so that event view can get it, and later by the index manipulated the data and updated runtime used few css tricks to illustrate the strike effect.
score:0
as mentioned in other answers, a possible solution is externalize the legend as plain html div, on which you have full control.
now, in chartjs v3 the chart.generatelegend()
function has been removed.
the maintainers, though, have published the so called htmllegend plugin which externalises the legend, here is the link:
html legend (external div) - chartjs docs
the plugin creates an interactive legend whose items can be clicked to show/hide datasets as in the original one.
note: although having a scrollable legend might come in handy, having so many items in a legend could make the chart illegible and should make one consider representing data in a different way, perhaps by splitting data in more charts or introducing search functions
score:1
i did not found any solution for this, but you can turn off legend if too many labels are to be shown (i did it in my project) - here is set to max 15 labels:
options : {
responsive: true,
maintainaspectratio: false,
layout: {
padding: {
left : 0,
right : 0,
top : 0,
bottom : 0
}
},
animation: {
duration : 5000
},
legend: {
display: this.chartvalues.length <= 15,
}
}
you can also make place for rendering charts bigger. add this to your scss file:
.chartjs-render-monitor{
height: 300px !important;
}
i hope it gonna help someone
Source: stackoverflow.com
Related Query
- How to fix chart Legends width-height with overflow scroll in ChartJS
- Why would a ChartJS chart end up with width 0 and height 0?
- How to dynamically set ChartJs line chart width based on dataset size?
- How to get the actual chart width and height in chart.js
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to create chartjs chart with data from database C#
- React chart : prevent chart's canvas scaling with height and width
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- How to display chart using Chartjs with JSON data in Laravel
- How to reduce the number of points shown on line chartjs chart with a large dataset?
- Bar chart with min height and zero values - ChartJs
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- Charts.js how to fix the height with more than 50 horizontal bars
- How can I fix the offset of the gradient to be aligned with the chart points(chart.js)?
- How to make a chart with chartjs and Angular?
- How do I display two datasets on a single chart with chartjs
- ChartJs - stacked bar chart with groups - how to create second x-axis with stack id
- Remove redundant legends on the chart using generateLabels with ChartJS v3
- How to fix size of mixed chart with bubble chart in Chart.js?
- How do you get the width of a datalabel from the Chartjs plugin after the chart animates?
- How to update Chartjs chart (react-chartjs-2) with dynamic data?
- Chart.js minimal width of Chart with scrollable overflow
- How to shrink the height and increase the line width of a custom Chartjs horizontal line?
- chart js 2 how to set bar width
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Chartjs random colors for each part of pie chart with data dynamically from database
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How to prevent first/last bars from being cut off in a chart with time scale
- ChartJS - Draw chart with label by month, data by day
More Query from same tag
- Drill Down Chart find Index returns -1
- Chart only prints out first value using jquery ajax php
- Pagination in Bar chart using ChartJS
- set background color to save canvas chart
- How to pass dynamic string as dataset in charts.js
- reveal.js with plotly.js and chart.js export pdf
- Is there a way to highlight a line on a line graph with hover?
- Chartjs - display radarchart lines from center to corner value
- turn off point values in radar chart
- Chart.js - How to set a line chart dataset as disabled on load
- ng2-charts tooltip and legend stopped working
- Chartjs: how can i create a graph with multiple jsons files?
- ChartJS - Set different hover-text than x-axis description
- Why won't my chart.js chart render in React?
- Is it possible to create different stepsize for different yAxis intervals on chartJs?
- dynamically add canvas for chart.js
- How to integrate basic ChartJs customizations when using react-chartjs-2?
- Hide/disable tootlip on specific graph values
- How do I add padding on the right of tooltip, but not the left in Chart.js?
- ChartJs custom tooltip position
- The bar that contains a low value is almost invisible on the chartjs
- How can I create custom tooltips for each data point in a graph?
- Leaflet polygon display charts after click
- Puppeteer with Chart.js
- set my chart min yaxis to 0
- React ChartJS 2 : Get data on clicking the chart
- ChartJS - Change legend to toggle buttons
- Making chartjs scrollable on the x-axis
- Radar chart - show values near vertices in chart.js
- Chart, X and Y-Axis labels are blurred in horizontal bar chart using chart.js