chart.js 2 - Is it possible to format tick labels with HTML? - chart.js

I have a chart that shows 3 datasets - 2 Line, 1 Bar.
I would like to be able to format the Y-2 axis labels in the screenshot below with HTML to allow me to show the values in each tick as bubbles to match the styling displayed on the line data points. (I am using the datalabels plugin to achieve the data point styling https://github.com/chartjs/chartjs-plugin-datalabels).
In addition to this I would like to have all labels with "XLabelLine1" and "XLabelLine2" to have a line break between them.
Is this possible? From looking at the docs it looks as if the axis labels can only be strings.

You are correct that the tick labels can only be strings and that the Chart.JS tick labels do not have HTML support. It's likely a plugin would need to be developed for this behavior. Sorry. :)

Related

Chart.js scatter/bubble pointstyle custom text

I'm looking for a solution in which custom text is rendered instead of a point for a scatter or bubble diagram using chart.js. For example, if plotting baseball players' batting average vs slugging percentage, I want the player's name to appear centered horizontally and vertically over the underlying x,y coordinate, such as 'MANTLE' or 'RUTH', instead of the typical dot/square/triangle/bubble pointstyles. I noticed a callback function lets me program custom axis labels, but I need to do something similar for the actual point of the graph.
If this is not possible, can you recommend another library that can do this.
Thank you in advance...
chartjs-plugin-datalabels does what you're looking for. The positioning of the labels is largely customizable. A custom label formatter function for example lets you display text other than the data values.
Please take a look at the chartjs-plugin-datalabels samples, especially at Custom Labels.
Keep in mind that this plugin registers itself globally, meaning that once imported, all charts will display labels. In case you want it enabled only for a few charts, you first need to unregister it globally. Then, you can enabled the plugin for specific charts.

how to highlight a specific area on chartjs line chart

I am using chartjs to draw a line chart on my application. I have dates onx-axis but as a category scale. Means labels are strings but are dates. On the y-axis i have numeric values. I am changing the chart on some functionality and after change i want to highlight some area of the chart. Is there any way i can highlight an area on the line chart? I have searched but did not find anything.
I want to do this pragmatically like there are some specific dates which i want to highlight so i want to have this type of effect.
Any kind of help would be much appreciated. I am very beginner in charts and javascript stuff.
P.S this is specifically for the line chart not for the doughnut
I use this https://github.com/chartjs/chartjs-plugin-annotation lib to do something like this.check on it. I think this will helpful.

Displaying labels for grouped datasets in ChartJS clustered column graph

Not sure how to even define this question, so bear with me!
First, I want to display multiple unrelated datasets, side by side.
Second, for each dataset, I'd like to have column-based lables (default for each column), then an overall "grouped" label for the dataset.
I can "fake" the appearance of this chart by entering a "zero" column entry, creating the gap between the "datasets" I have (even though in ChartJS is just one dataset).
The text line one is default behaviour with ChartJS to display the column label. However getting a "grouped" label to appear is beating me! What I've ended up doing is generating the chart label-less, then doing some funky HTML hacks to get the labels back with the grouped text I need. This approach is not scalable.
Can anyone point me in the right direction for this? Doesn't have to be ChartJS powered.

It is possible to hide part of labels google chart

I want to hide couple labels, first 2 and last 2 in axis X.
I want to disable black line at the bottom of the graph.
I'm able to do it after the chart is loaded - using javascript and change it dynamically. When I add new data and use draw method, Graph is overwriting my dynamic stylesheets changes. I was trying to set it as an option in graph initializer but I couldn't find the solution for that.
I use areaChart.
It was 3 years ago. I don't need it anymore. I'm leaving this question for others.
It's a little hard understanding what you're trying to do, but I think I get it.
As I read it, you want to eliminate two variables from your DataTable when you plot your chart (to prevent them from being in the legend)? Assuming that's the case, you can either take them out of the data table, or use a ChartWrapper on your object, and set the view:{columns:[x,y,z]} option to the ChartWrapper. Assuming you can't change the DataTable, or a ChartWrapper isn't an option, and you just want to not have certain plotted objects appear in your chart but not in the legend, you want to set the series option. For example, assuming three columns in your DataTable, you can hide the third item as:
series: [{visibleInLegend:true}, {visibleInLegend:true}, {visibleInLegend:false}],
Second of all, if you want to hide the horizontal axis, you need to have continuous data, and set hAxis.baselineColor to 'clear'.
To hide some of the tick-mark labels, use ticks: ticklist to label the axis, and for some of the labels in ticklist use an {v:value,f:label} structure definition, with a zero-length string for the label.
Here's an example. Note the omitted labels for some of the ticks on each vertical axis. View source to see how I did it:
http://www.sealevel.info/co2_and_ch4c.html
Note the tick list definitions. This one is for the left vertical axis:
var vticklist1 = [{v:235,f:''},{v:250,f:''},275,300,325,350,375,400,{v:425,f:'ppmv'}];
The first & second ticks (at the bottom, for values 235 and 250) display no labels. The next six ticks, for values 275-400, display normally. The last (top) tick displays as "ppmv" instead of 425. The result looks like this:

Google Charts API - Overlapping X axis labels

I have a chart generated from Google Charts that can be found here: Chart generate by Google Charts API. As you can see the x axis labels are being overlapped.
Anyone knows how to solve this?
See the docs under Bar Width and Spacing (chbh). There's this snippet:
a - space_between_bars and space_between_groups are given in
absolute units (or default absolute values, if not specified). Bars
will be resized so that all bars will fit in the chart.
So just add chbh=a to the options. Here's the example with this option added.