gionkunz / chartist-plugin-pointlabels Goto Github PK
View Code? Open in Web Editor NEWPoint Labels Plugin for Chartist.js
License: Do What The F*ck You Want To Public License
Point Labels Plugin for Chartist.js
License: Do What The F*ck You Want To Public License
Plugin is showing just [object Object] instead of data from series. Problem is visible on demo page as well:
https://gionkunz.github.io/chartist-js/plugins.html
I am trying to use this plugin for my line charts, but the tags are not being inserted after each element like in the example on chartist shows. (https://gionkunz.github.io/chartist-js/plugins.html#point-label-plugin). I have included the script link towards the bottom of my code, placed before my script for creating the charts:
<script src="js/plugins/chartist-plugin-pointlabels-master/src/scripts/chartist-plugin-pointlabels.js"></script>
<script>
// Loads per Broker (Red Chart)
new Chartist.Line('#chart1', {
labels: ['<?php echo $labels;?>'],
series: [
[<?php echo $loads_per_broker_data;?>]
]
}, {
plugins: [
Chartist.plugins.tooltip({
anchorToPoint: true
}),
Chartist.plugins.ctPointLabels({
textAnchor: 'middle',
labelInterpolationFnc: function(value) {return '$' + value.toFixed(2)}
})
],
low: 0,
showArea: true
});
// Loads per Carrier (Yellow/Orange Chart)
new Chartist.Line('#chart2', {
labels: ['<?php echo $labels;?>'],
series: [
[<?php echo $loads_per_carrier_data;?>]
]
}, {
plugins: [
Chartist.plugins.tooltip({
anchorToPoint: true
}),
Chartist.plugins.ctPointLabels({
textAnchor: 'middle'
})
],
low: 0,
showArea: true
});
// Margin % (Green Chart)
new Chartist.Line('#chart3', {
labels: ['<?php echo $labels;?>'],
series: [
[<?php echo $margin_percent_data;?>]
]
}, {
plugins: [
Chartist.plugins.tooltip({
anchorToPoint: true
}),
Chartist.plugins.ctPointLabels({
textAnchor: 'middle'
})
],
low: 0,
showArea: true
});
// Margin $ (Blue Chart)
new Chartist.Line('#chart4', {
labels: ['<?php echo $labels;?>'],
series: [
[<?php echo $margin_dollar_data;?>]
]
}, {
plugins: [
Chartist.plugins.tooltip({
anchorToPoint: true,
currency: '$'
}),
Chartist.plugins.ctPointLabels({
textAnchor: 'middle'
})
],
low: 0,
showArea: true
});
// Buy v. Market (Purple Chart)
new Chartist.Line('#chart5', {
labels: ['<?php echo $labels;?>'],
series: [
[<?php echo $buy_market_data;?>]
]
}, {
axisY: {
labelInterpolationFnc: function(value) {
return -value;
}
},
plugins: [
Chartist.plugins.tooltip({
anchorToPoint: true
}),
Chartist.plugins.ctPointLabels({
textAnchor: 'middle'
})
],
/*low: 0,*/
showArea: false
}).on('data', function(context) {
context.data.series = context.data.series.map(function(series) {
return series.map(function(value) {
return -value;
});
});
});
</script>
Great plugin, thanks for it. I tried it on a single line chart, it works like a charm. When I tried it on a multi line chart, the values seem to overlap. I understand that this is because of the overlap of the lines. Setting padding/margin/offset doesn't work since it doesn't differentiate one point from another point of a different line. Is there a workaround for this? Please let me know, thanks!
I could not make this work properly on barcharts.
This is my code:
new Chartist.Bar('#demo_03', {
labels: ['Corea del Sur' ,'Noruega' ,'Luxemburgo' ,'Países Bajos' ,'Islandia' ,'Dinamarca' ,'Suecia' ,'Reino Unido' ,'Alemania' ,'Finlandia' ,'Suiza' ,'Irlanda' ,'Estonia' ,'Australia' ,'Francia' ,'Austria' ,'Bélgica' ,'Canadá', 'España' ,'Rep. Checa' ,'Eslovaquia' ,'Polonia' ,'Nva. Zelandia' ,'Hungría' ,'Italia' ,'Eslovenia' ,'Letonia' ,'Turquía' ,'Israel' ,'Portugal' ,'EEUU' ,'Lituania' ,'Chile' ,'Grecia' ,'Japón' ,'Costa Rica' ,'Brasil' ,'México' ,'Colombia' ],
series: [
[98.80 , 97.05 , 97.04 , 96.66 , 96.48 , 94.34 , 93.80 , 93.48 , 92.14 , 91.95 , 90.62 , 86.71 , 86.19 , 85.89 , 85.87 , 85.09 , 84.79 , 83.90, 81.93 , 81.65 , 80.52 , 80.45 , 80.00 , 79.18 , 78.51 , 78.42 , 77.34 , 76.34 , 74.29 , 74.05 , 73.37 , 71.75 , 71.56 , 69.13 , 67.10 , 64.84 , 49.20 , 47.02 , 41.80 ]
]
}, {
plugins: [
Chartist.plugins.ctPointLabels({
textAnchor: 'left',
align: 'center'
}),
Chartist.plugins.ctTargetLine({
value: 83
})
],
chartPadding: {
right: 32
},
axisY: {
offset: 20,
},
axisX: {
offset: 120,
}
});
This is my result:
I tried with this changes in the code, to no avail.
Any pointers or help is appreciated
Hi, I've noted that relying on constructor.name to verify the type of chart causes the plugin not to work when using code obfuscators or minimifiers. In this plunkr the problem is reproduced.
Maybe another way of checking the chart type could be used, or maybe the checking could be removed altogether.
Hi,
I am trying to use this plugin in react project but got an error. It shows TypeError: Cannot read property 'plugins' of undefined
Could you help? Thx in advanced.
Some of the code:
import ChartistGraph from "react-chartist";
import { ChartistLib, Chartist } from "chartist";
...
render() {
let chartOptions={
axisX: {
showGrid: fal
},
axisY: {
showGrid: false,
showLabel: false,
low: 0,
high: this.state.weeklySalesStatisticsBarChartData.high,
offset: 0,
},
fullWidth: true,
offset: 0,
chartPadding: 25,
plugins: [
Chartist.plugins.ctPointLabels({
textAnchor: 'middle'
})
]
};
return (
<ChartistGraph
className="height-200 lineChart lineChartShadow"
data={this.state.weeklySalesStatisticsBarChartData}
type="Line"
options={chartOptions}
listener={{
created: data => {
let circleRadius = 4;
if (data.type === "point") {
let circle = new ChartistLib.Svg("circle", {
cx: data.x,
cy: data.y,
r: circleRadius,
'class': "ct-point-circle"
});
data.element.replace(circle);
} else if (data.type === "label") {
// adjust label position for rotation
const dX = data.width / 2 + (30 - data.width);
data.element.attr({ x: data.element.attr("x") - dX });
}
}
}}
/>
)
Hi,
can the label be positioned on top of the bar? i looked into the options and i only found a Y offset.
any practice to share ?
thank you
hi, currently I use pointlabels plugin in development mode. I already installed the plugin and works on development mode, but when I build it to production mode, the pointlabels doesnt work. it doesnt appear. is there any idea how to show it on production mode?
I have a website which shows the progress of projects.
I really need to add the point labels but I only use Bar charts, is it possible to customize this plugin to work with Bar chart?
Hi, I've found chartist to be an excellent tool. I customized my charts to a great extent by modifying the css file.
However, when I try to get any of the proposed plugins that you posted, I cannot get the to work. I'm srry if this is a newbie question, but that's what I'm. What I've tried so far are the following options:
OPTION A:
$scope.config = {
high: 15,
low: 0,
showArea: true,
showLine: true,
showPoint: true,
fullWidth:true,
axisY: {
showLabel: false,
showGrid: false,
offset: 5
},
axisX: {
showLabel: false,
showGrid: false
},
plugins: [
ctPointLabels({
textAnchor: 'middle'
}),
],
};
OPTION B:
It's worth noting that the chart is working fine with the original config options (with the the " plugins" section commented). The original working options are:
$scope.config = {
high: maxVal,
low: 0,
showArea: true,
showLine: true,
showPoint: showPoints,
fullWidth:true,
axisY: {
showLabel: false,
showGrid: false,
offset: 5
},
axisX: {
showLabel: false,
showGrid: false
}
// ,
// plugins: [
// ctPointLabels({
// textAnchor: 'middle'
// }),
// ],
};
Thanks for any help or guide on how to properly setup the workspace for plugins (I checked the chartistjs plugin section, but I couldn't find a solution)
When working with webpack import, this plugin requires an
window.Chartist = Chartist;
assignment before doing a require.
Other plugins such as
'chartist-plugin-legend'
'chartist-plugin-tooltips'
work fine without it.
Hello! If not set, labelInterpolationFnc
will use Chartist.noop. However, my chart shows undefined
instead of 0
.
I had to apply this function to fix this:
{
labelInterpolationFnc: v=>v?v:0
}
Taking a look at the "addLabel" Function in "chartist-plugin-pointlabels":
function addLabel(position, data) {
// if x and y exist concat them otherwise output only the existing value
var value = data.value.x !== undefined && data.value.y ?
(data.value.x + ', ' + data.value.y) :
data.value.y || data.value.x;
data.group.elem('text', {
x: position.x + options.labelOffset.x,
y: position.y + options.labelOffset.y,
style: 'text-anchor: ' + options.textAnchor
}, options.labelClass).text(options.labelInterpolationFnc(value));
}
When y is falsey we default to the data.value.x; but when y = "0" perhaps we want to show a label 0. Is this the expected behavior? Or should we have a "!== undefined" after data.value.y as well?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.