Percentages on Slices of ZingChart Pie Chart - zingchart

(I asked a similar question once before, but the issue has cropped up again.)
I have a very simple pie chart using ZingCharts, but even though all of the examples on the ZingCharts site show percentages on each slice, I can't get the percentages to show. Note that I am using value boxes. I am using the most recent version of ZingCharts from the CDN: https://cdn.zingchart.com/zingchart.min.js
Note that I am looking for the percentage to appear ON the slice, not in the value box which is text attached to each slice by a line.
Here is my code:
<div id="pie-chart"> </div>
<script>
var slices = var slices = slices = [
{"values":[59],"text":"USA"},
{"values":[55],"text":"UK"}
];
var chartData = {
"type":"pie",
"plot":{
"value-box":{
"visible":true,
"placement":"out",
"text":"%t (%v)"
}
},
"series": slices
};
zingchart.render({
id:"pie-chart",
data: chartData,
height:400,
width:"100%"
});
</script>
I want to use a standard pie chart, not a pie chart with more effects.

To show the percentage value on charts, you would need to use the %npv (node-percent-value) token instead of %v which displays the raw value. More information in the pie chart types page : http://www.zingchart.com/docs/chart-types/pie/
Note that the default functionality for a value box is
"value-box" : {
"placement" : "in",
"text" : "%npv%"
}
Therefore, you can choose to omit that from your JSON. In the example below, I have shown the JSON with the options explicitly.
var slices = [
{"values":[59],"text":"USA"},
{"values":[55],"text":"UK"}
];
var chartData = {
"type":"pie",
"series": slices,
"plot" : {
"value-box" : {
"placement" : "in",
"text" : "%npv%"
}
}
};
zingchart.render({
id:"pie-chart",
data: chartData,
height:400,
width:"100%"
});
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<div id="pie-chart"></div>

Related

Time Series aren't working

I was trying to set up a Zingchart timeline series but it isn't working properly. The line is incorrect, the date doesn't get converted and the y axis shows also comepletely wrong entries.
Is there anyone who can see what I'm doing wrong?
Thanks a lot
<script>
jQuery(document).ready(function($) {
zingchart.render({
"id":"myChart2",
"adjustLayout": "true",
"scale-x":{
"transform":{
"type":"date",
"all":"%d.%m.%Y",
"item":{
"visible":"false"
}
},
"auto-fit":"true"
},
"data":{
"type":"line",
"title":{
"text":"Series Data Objects"
},
"series": [
{
"line-color":"#ff0000",
"values": [["825552000000","248.22"],["828057600000","248.08"],["830822400000","256.50"],["833500800000","255.54"],["835920000000","259.12"],["838771200000","238.70"],["841449600000","240.49"],["844041600000","241.09"],["846633600000","241.36"],["849312000000","253.61"],["851990400000","259.85"],["854668800000","293.11"],["857088000000","297.88"],["859420800000","308.32"],["862358400000","319.51"],["864950400000","332.99"],["867628800000","359.04"],["870307200000","367.30"],["872812800000","358.41"],["875577600000","362.73"],["878256000000","335.60"],["880675200000","338.64"],["883526400000","333.78"],["886118400000","347.69"],["888624000000","374.74"],["891302400000","414.51"],["893894400000","425.38"],["896400000000","455.20"],["899164800000","449.35"],["901843200000","444.80"],["904521600000","373.21"],["907113600000","331.78"],["909792000000","350.40"],["912384000000","361.39"],["915062400000","352.06"],["917568000000","339.32"],["919987200000","351.13"],["922838400000","373.90"],["925430400000","400.78"],["928108800000","403.39"],["930700800000","411.89"],["933292800000","412.81"],["936057600000","423.43"],["938649600000","432.41"],["941328000000","434.90"],["943920000000","460.06"],["946512000000","488.37"],["949276800000","526.76"],["951782400000","546.37"],["954460800000","552.29"],["957052800000","550.44"],["959731200000","557.94"],["962323200000","565.27"],["965001600000","580.34"],["967680000000","592.46"],["970185600000","593.84"],["972950400000","586.73"],["975542400000","587.99"],["978220800000","574.41"],["980899200000","591.06"],["983318400000","584.99"],["985910400000","556.95"],["988588800000","564.08"],["991267200000","573.05"],["993772800000","562.91"],["996537600000","524.32"],["999216000000","497.57"],["1001635200000","397.34"],["1004486400000","411.61"],["1007078400000","428.81"],["1009756800000","442.50"],["1012435200000","429.54"],["1014854400000","421.18"],["1017532800000","450.53"],["1020124800000","472.24"],["1022803200000","498.40"],["1025222400000","468.36"],["1028073600000","429.21"],["1030752000000","421.15"],["1033344000000","377.54"],["1036022400000","358.54"],["1038528000000","377.31"],["1041292800000","367.59"],["1043971200000","345.28"],["1046390400000","333.31"],["1049068800000","339.64"],["1051660800000","380.18"],["1054252800000","393.14"],["1056931200000","400.88"],["1059609600000","413.35"],["1062115200000","442.21"],["1064880000000","452.48"],["1067558400000","477.75"],["1069977600000","481.48"],["1072742400000","489.31"],["1075420800000","526.61"],["1078012800000","540.60"],["1080691200000","535.48"],["1083283200000","562.73"],["1085702400000","566.69"],["1088553600000","595.42"],["1091145600000","582.42"],["1093910400000","575.98"],["1096502400000","584.63"],["1099008000000","574.38"],["1101772800000","582.98"],["1104451200000","603.91"],["1107129600000","635.69"],["1109548800000","666.30"],["1112227200000","676.75"],["1114732800000","659.07"],["1117497600000","673.11"],["1120089600000","694.10"],["1122595200000","740.74"],["1125446400000","756.92"],["1128038400000","780.60"],["1130716800000","756.80"],["1133308800000","752.26"],["1135900800000","769.52"],["1138665600000","820.12"],["1141084800000","865.22"],["1143763200000","889.63"],["1146182400000","936.09"],["1149033600000","894.71"],["1151625600000","877.78"],["1154304000000","895.81"],["1156982400000","925.75"],["1159488000000","949.28"],["1162252800000","992.61"],["1164844800000","1021.22"],["1167350400000","1089.17"],["1170201600000","1164.23"],["1172620800000","1156.02"],["1175212800000","1195.74"],["1177891200000","1293.23"],["1180569600000","1339.80"],["1183075200000","1349.97"],["1185840000000","1359.15"],["1188518400000","1330.35"],["1190937600000","1336.06"],["1193788800000","1402.84"],["1196380800000","1187.53"],["1198800000000","1302.28"],["1201737600000","1125.40"],["1204243200000","1140.95"],["1206921600000","1094.89"],["1209513600000","1142.30"],["1212105600000","1145.74"],["1214784000000","1095.27"],["1217462400000","1033.11"],["1219968000000","1055.30"],["1222732800000","931.33"],["1225411200000","708.98"],["1227744000000","621.59"],["1230595200000","616.87"],["1233273600000","603.03"],["1235692800000","552.63"],["1238457600000","539.30"],["1241049600000","638.71"],["1243555200000","684.26"],["1246320000000","695.27"],["1248998400000","742.61"],["1251676800000","791.45"],["1254268800000","813.03"],["1256860800000","796.28"],["1259539200000","773.35"],["1262131200000","802.69"],["1264723200000","839.72"],["1267142400000","823.41"],["1269993600000","893.27"],["1272585600000","918.51"],["1275264000000","887.80"],["1277856000000","877.87"],["1280448000000","905.59"],["1283212800000","917.29"],["1285804800000","950.25"],["1288310400000","997.97"],["1291075200000","1010.56"],["1293667200000","1091.59"],["1296432000000","1108.11"],["1298851200000","1125.12"],["1301529600000","1139.23"],["1304035200000","1172.38"],["1306800000000","1159.70"],["1309392000000","1079.62"],["1311897600000","992.65"],["1314748800000","910.04"],["1317340800000","842.27"],["1320019200000","865.83"],["1322611200000","835.59"],["1325203200000","827.32"],["1327968000000","889.40"],["1330473600000","939.11"],["1333065600000","947.00"],["1335744000000","952.62"],["1338422400000","890.97"],["1340928000000","892.26"],["1343692800000","900.41"],["1346371200000","892.48"],["1348790400000","918.34"],["1351641600000","917.96"],["1354233600000","908.92"],["1356652800000","934.70"],["1359590400000","992.75"],["1362009600000","1018.12"],["1364428800000","1029.32"],["1367280000000","1034.59"],["1369958400000","1048.29"],["1372377600000","1036.88"],["1375228800000","1063.80"],["1377820800000","1109.08"],["1380499200000","1140.76"],["1383177600000","1180.44"],["1385683200000","1203.78"],["1388361600000","1227.91"],["1391040000000","1266.04"],["1393545600000","1277.03"],["1396224000000","1316.99"],["1398816000000","1335.68"],["1401408000000","1326.99"],["1404086400000","1335.88"],["1406764800000","1316.64"],["1409270400000","1307.37"],["1412035200000","1264.57"],["1414713600000","1260.85"],["1417132800000","1286.13"],["1419897600000","1270.55"],["1422576000000","1149.42"],["1424995200000","1263.92"],["1427760000000","1321.38"],["1430352000000","1344.94"],["1432857600000","1355.69"],["1435622400000","1305.78"],["1438300800000","1330.99"],["1440979200000","1317.52"],["1443571200000","1296.63"],["1446163200000","1337.35"],["1448841600000","1397.59"],["1451433600000","1423.16"],["1454025600000","1358.41"],["1456704000000","1397.02"],["1459382400000","1477.83"],["1461888000000","1510.31"],["1464652800000","1584.98"],["1467244800000","1541.25"],["1469750400000","1633.75"],["1472601600000","1755.57"],["1475193600000","1781.34"],["1477872000000","1763.37"],["1480377600000","1730.74"],["1483056000000","1799.97"],["1485820800000","1888.34"],["1488240000000","2006.37"],["1490918400000","2073.79"],["1493337600000","2197.66"],["1496188800000","2250.52"],["1498780800000","2256.34"],["1501459200000","2294.53"],["1504137600000","2264.10"],["1506643200000","2350.68"],["1509062400000","2407.96"],["1512000000000","2473.35"],["1514505600000","2539.02"],["1517356800000","2590.74"],["1519776000000","2530.56"],["1521417600000","2502.57"]]
},
]
}
});
});
</script>
<div id="myChart2" class="chart"></div>
JSFiddle
The reason the chart line is not displaying correctly is because of the way you formatted your values. You have your values in quotation marks like this: ["825552000000","248.22"].
The way the values should be formatted is WITHOUT quotation marks. The values should be formatted as such: [825552000000,248.22].
Once you remove the quotation marks on all of your values the chart line will display correctly.
Hope this helps.

AmChart export change font color on export

i have i problem and tried different solutions, but no success.
I have an amChartXY chart, which has white labels and legend text is white, but when i want to build custom pdf report, i cannot convert those white text into black.
First i have a function which exports chart to base64 string, and i want there to convert the text color to black, but it won't work.
Here is a code snippet of a menu item, that converts to SVG that is saved to global array object.
menu: [
{
class: "",
label: "Save to draft",
click: function() {
var overrideObject = {
backgroundColor : "rgba(255,255,255,1)",
color : "#000",
legend : {
color : "#000"
}
};
var chartObject = this;
chartObject.capture(overrideObject, function () {
chartObject.toJPG({}, function (base64) {
// charts is global array
charts.push({
name: customName,
chart: base64
});
});
});
}
},
Here the overrideObject is changing the backgroundColor attribute with white ( before is was transparent ) but it's not changing font color. Also i have tried different attributes to add, but nothing seems to work.
Is this possible at capture time ?
Here are some images preview of what i want to accomplish :
AmChart for export isn't that well documented, so any feedback would be welcome
The overrideObject you're passing only accepts the same parameters listed in the list of export settings. If you need to change the appearance of specific elements on the chart, you need to use the reviver callback mentioned in the annotation settings section to selectively apply your modifications. For example, here's how to target the value axis labels:
"export": {
"enabled": true,
"reviver": function(nodeObj) {
if (nodeObj.className === 'amcharts-axis-label' && nodeObj.svg.parentNode.classList.contains('amcharts-value-axis')) {
nodeObj.fill = 'rgba(255,0,0,1)';
}
},
// ...
}
Note that you need to use SVG attributes to change the appearance, so you'll have to set the fill to change the color of the text element.
Codepen demo

Zing scatter chart node at border gets chopped off

I am using zing chart in my application with scatter & Line chart, everything working fine but the only problem is the scatter chart node circle gets chopped off when it is at extreme end of the chart.
Tried increasing margin, setting offset, z-index and nothing worked for me till now, any solution is appreciated.
Regards,
Smruti
At this time of writing, the only way I can think of is to adjust your scale-x and scale-y values manually based off of the values you are inserting into the chart. Perhaps a function to preprocess the data to determine a maximum value before rendering a chart would be best. In the example below, I am creating 2 charts. One with set values but does not compensate for markers cutting off the edge, and another which has a helper function to increase the maximum y value by 10%.
HOWEVER! There is an unreleased attribute that will be on the next release we are scheduling within the next week or two. It exposes an attribute called mask-tolerance which will allow markers to bleed past the plot area. Keep an eye out for that as that is the optimum solution. --I'm on the ZingChart team; let me know if you have any further questions.
var myConfig = {
type: "scatter",
plot : {
marker : {
size : 10
}
},
series : [
{
values : [35,42,67,89,25,100,67,100]
}
],
plotarea :{
padding : "10px"
},
scaleY : {
values : "0:90:10"
}
};
zingchart.render({
id : 'myChart',
data : myConfig,
height: 200,
width: 300
});
function preProcessData(){
var myValues = [35,42,67,89,25,100,67,100];
var maxVal = Math.max.apply(null,myValues);
var maxScale = maxVal + Math.floor(maxVal * 0.10);
return {
type: "scatter",
plot : {
marker : {
size : 10
}
},
series : [
{
values : myValues
}
],
plotarea :{
padding : "10px"
},
scaleY : {
values : "0:"+maxScale+":10"
}
};
}
zingchart.render({
id : 'myChart2',
data : preProcessData(),
height: 200,
width: 300
});
<html>
<head>
<script src= 'https://cdn.zingchart.com/zingchart.min.js'></script>
</head>
<body>
<div id='myChart'></div>
<div id="myChart2"></div>
</body>
</html>

ZingChart how to modify node upon click/select

I am using ZingChart for a standard bar graph. I have the selected state for individual bars working as I would like but for one thing. Is there a way to show the value box (set to visible:false globally) to show just for the selected node when it is clicked/selected? I was able to make the value box for every node show in a click event I added to call an outside function using the modifyplot method but I don't see a similar method for nodes such as modifynode. If this is not an option, is there any way to insert a "fake" value box the markup of which would be created on the fly during the click event and have that element show above the selected node? Below is my render code for the chart in question. Thanks for your time!
zingchart.render({
id: "vsSelfChartDiv",
width: '100%',
height: '100%',
output: 'svg',
data: myChartVsSelf,
events:{
node_click:function(p){
zingchart.exec('vsSelfChartDiv', 'modifyplot', {
graphid : 0,
plotindex : p.plotindex,
nodeindex : p.nodeindex,
data : {
"value-box":{
"visible":true
}
}
});
var indexThis = p.nodeindex;
var indexDateVal = $('#vsSelfChartDiv-graph-id0-scale_x-item_'+indexThis).find('tspan').html();
updateTop(indexDateVal);
}
}
});
You'd probably be better off using a label instead of a value-box. I've put together a demo here.
I'm on the ZingChart team. Feel free to hit me up if you have any more questions.
// Set up your data
var myChart = {
"type":"line",
"title":{
"text":"Average Metric"
},
// The label below will be your 'value-box'
"labels":[
{
// This id allows you to access it via the API
"id":"label1",
"text":"",
// The hook describes where it attaches
"hook":"node:plot=0;index=2",
"border-width":1,
"background-color":"white",
"callout":1,
"offset-y":"-30%",
// Hide it to start
"visible":false,
"font-size":"14px",
"padding":"5px"
}
],
// Tooltips are turned off so we don't have
// hover info boxes and click info boxes
"tooltip":{
"visible":false
},
"series":[
{
"values":[69,68,54,48,70,74,98,70,72,68,49,69]
}
]
};
// Render the chart
zingchart.render({
id:"myChart",
data:myChart
});
// Bind your events
// Shows label and sets it to the plotindex and nodeindex
// of the clicked node
zingchart.bind("myChart","node_click",function(p){
zingchart.exec("myChart","updateobject", {
"type":"label",
"data":{
"id":"label1",
"text":p.value,
"hook":"node:plot="+p.plotindex+";index="+p.nodeindex,
"visible":true
}
});
});
// Hides callout label when click is not on a node
zingchart.bind("myChart","click",function(p){
if (p.target != 'node') {
zingchart.exec("myChart","updateobject", {
"type":"label",
"data":{
"id":"label1",
"visible":false
}
});
}
});
<script src='http://cdn.zingchart.com/zingchart.min.js'></script>
<div id="myChart" style="width:100%;height:300px;"></div>

Place Highstock inside a SVG

can you help me to place a Highchart inside a SVG element instead of an HTML . Cascaded elements work fine. I have already done it with the jquery SVG plot. But Highchart throws an error 13. What can i do?
Kind regards
Markus Breitinger
You can generate chart in div, which will have negative margin. Then use getSVG() function and paste it ot svg element.
http://api.highcharts.com/highcharts#Chart.getSVG()
Unfortunately it is not suppored, highcharts renders the chart in additional divs and adds elements like labels/datalabels as html objects.
But you can copy the SVG of highstock in you SVG. But you will lose all attached events.
Like drag and drop, click ....
Here an Example of it.
http://jsfiddle.net/L6SA4/10/
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
// Create a hidden and not attached div container.
var div = $('<div>This is an hidden unatached container.</div>');
// Create the chart
div.highcharts('StockChart', {
chart: {
width: 480,
height: 400,
events: {
load: function () {
// If hidden div was generated, take the svg content and put it into svg.
var stockSvg = $('svg', this.container);
var svgObj = $('#mySvg').svg();
// Force position of highstock
stockSvg.attr('x', 20);
stockSvg.attr('y', 30);
// Replace ugly rect with highstock
$('#container', svgObj).replaceWith(stockSvg);
}
}
},
series : [{
name : 'AAPL',
data : data,
tooltip: {
valueDecimals: 2
}
}]
});
});

Resources