HTMLcopy
1
<button id="jsonButton" onclick="showJson()">Show JSON config</button>
2
<div id="container"></div>
CSScopy
15
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
button {
8
margin: 10px 0 0 10px;
9
}
10
#container {
11
position: absolute;
12
width: 100%;
13
top: 35px;
14
bottom: 0;
15
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// chart type
4
chart = anychart.polar();
5
6
chart.title().text("Polar Chart");
7
8
chart.line([
9
{x: 0, value: 0},
10
{x: 10, value: 1},
11
{x: 20, value: 2},
12
{x: 30, value: 3},
13
{x: 40, value: 4},
14
{x: 50, value: 5},
15
{x: 60, value: 6},
16
{x: 70, value: 7},
17
{x: 80, value: 8},
18
{x: 90, value: 9},
19
{x: 100, value: 10}
20
]).tooltip().enabled(false);
21
22
chart.xScale().maximum(100).ticks().interval(10);
23
24
chart.yScale().ticks().interval(2);
25
26
chart.xAxis().labels().fontWeight(900);
27
chart.container("container").draw();
28
});
29
30
function showJson(){
31
var display = document.createElement("div");
32
display.style.position = "absolute";
33
display.style.width = "60%";
34
display.style.height = "40%";
35
display.style.resize = "both";
36
display.style.padding = "3px";
37
display.style.top = 0;
38
display.style.left = 0;
39
display.style.right = 0;
40
display.style.backgroundColor = "rgba(255, 255, 255, 0.9)";
41
display.style.border = "1px solid #999999";
42
display.style.zIndex = 90;
43
display.style.whiteSpace = "pre";
44
display.style.overflow = "scroll";
45
display.style.margin = "auto";
46
47
// create JSON config
48
var chartJson = chart.toJson();
49
50
// parse JSON
51
display.innerHTML = highLighter(JSON.stringify(chartJson, undefined, 2));
52
var body = document.getElementsByTagName("body")[0];
53
body.appendChild(display);
54
var jsonButton = document.getElementById("jsonButton");
55
jsonButton.innerHTML = "Hide JSON config";
56
jsonButton.onclick = function() {
57
body.removeChild(display);
58
jsonButton.onclick = showJson;
59
jsonButton.innerHTML = "Show JSON config";
60
};
61
}
62
63
// highlight JSON
64
function highLighter(strJson){
65
json = strJson.replace(/&/g, "&").replace(/</g,"<").replace(/>/g, ">");
66
return strJson.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
67
var cls = "number";
68
if (/^"/.test(match)) {
69
if (/:$/.test(match)) {
70
cls = "key";
71
return "<span style=\"color: #718C00;\">" + match.substr(0, (match.length - 1)) + "<a style=\"color:black;\">:</a></span>";
72
}
73
}
74
return "<span style='color: darkorange;'>" + match + "</span>";
75
});
76
}