javascript - Amcharts - HTML tags in some Labels -
i use following chart: http://www.amcharts.com/demos/stacked-bar-chart-with-negative-values/#theme-none
now want add html tags labels. (not all.)
example: (here wanna use strong)
"dataprovider": [{ "age": "<strong>85+</strong>", "male": -0.1, "female": 0.3 }, { "age": "80-54", "male": -0.2, "female": 0.3 }, ..... ],
the category axis labels in amcharts svg nodes , therefore not support html tags.
what can target specific labels using css.
to that, first need enable application of css classess chart elements, setting "addclassnames": true
.
then target labels using css. each category axis label has class "amcharts-axis-label"
set. can target first 1 using css's nth-child
selector:
.amcharts-category-axis .amcharts-axis-label:nth-child(1) tspan { font-weight: bold; }
(i used .amcharts-category-axis
selector value axis labels not targeted this)
here's whole working chart above working:
var chart = amcharts.makechart("chartdiv", { "type": "serial", "rotate": true, "addclassnames": true, "marginbottom": 50, "dataprovider": [{ "age": "85+", "male": -0.1, "female": 0.3 }, { "age": "80-54", "male": -0.2, "female": 0.3 }, { "age": "75-79", "male": -0.3, "female": 0.6 }, { "age": "70-74", "male": -0.5, "female": 0.8 }, { "age": "65-69", "male": -0.8, "female": 1.0 }, { "age": "60-64", "male": -1.1, "female": 1.3 }, { "age": "55-59", "male": -1.7, "female": 1.9 }, { "age": "50-54", "male": -2.2, "female": 2.5 }, { "age": "45-49", "male": -2.8, "female": 3.0 }, { "age": "40-44", "male": -3.4, "female": 3.6 }, { "age": "35-39", "male": -4.2, "female": 4.1 }, { "age": "30-34", "male": -5.2, "female": 4.8 }, { "age": "25-29", "male": -5.6, "female": 5.1 }, { "age": "20-24", "male": -5.1, "female": 5.1 }, { "age": "15-19", "male": -3.8, "female": 3.8 }, { "age": "10-14", "male": -3.2, "female": 3.4 }, { "age": "5-9", "male": -4.4, "female": 4.1 }, { "age": "0-4", "male": -5.0, "female": 4.8 }], "startduration": 1, "graphs": [{ "fillalphas": 0.8, "linealpha": 0.2, "type": "column", "valuefield": "male", "title": "male", "labeltext": "[[value]]", "clustered": false, "labelfunction": function(item) { return math.abs(item.values.value); }, "balloonfunction": function(item) { return item.category + ": " + math.abs(item.values.value) + "%"; } }, { "fillalphas": 0.8, "linealpha": 0.2, "type": "column", "valuefield": "female", "title": "female", "labeltext": "[[value]]", "clustered": false, "labelfunction": function(item) { return math.abs(item.values.value); }, "balloonfunction": function(item) { return item.category + ": " + math.abs(item.values.value) + "%"; } }], "categoryfield": "age", "categoryaxis": { "gridposition": "start", "gridalpha": 0.2, "axisalpha": 0 }, "valueaxes": [{ "gridalpha": 0, "ignoreaxiswidth": true, "labelfunction": function(value) { return math.abs(value) + '%'; }, "guides": [{ "value": 0, "linealpha": 0.2 }] }], "balloon": { "fixedposition": true }, "chartcursor": { "valueballoonsenabled": false, "cursoralpha": 0.05, "fullwidth": true }, "alllabels": [{ "text": "male", "x": "28%", "y": "97%", "bold": true, "align": "middle" }, { "text": "female", "x": "75%", "y": "97%", "bold": true, "align": "middle" }] });
#chartdiv { width: 100%; height: 500px; } .amcharts-category-axis .amcharts-axis-label:nth-child(1) tspan { font-weight: bold; }
<script src="http://www.amcharts.com/lib/3/amcharts.js"></script> <script src="http://www.amcharts.com/lib/3/serial.js"></script> <div id="chartdiv"></div>
Comments
Post a Comment