Description
This chart contains a PieSeries with a label centered over each piece.
Source Code
- <script type=”text/javascript”>
- //
- // Define the CSS in the header:
- // <style type=”text/css” media=”screen,print”>
- // .PiePieceLabel { position: absolute; background-color: #fff; border: 1px solid #999; padding: 2px;
- // opacity: 0.8; filter: Alpha(opacity:80); }
- // </style>
- //
- // Define variables to store references to the chart and series
- var myChart, mySeries = undefined;
- // After drawing is complete, create and/or reposition pie piece captions
- function doAfterDraw(chart) {
- // Verify series has been created
- if (mySeries != undefined) {
- var piePoints = mySeries.getPoints();
- // Loop through the list of pie series points
- for (var i = 0; i < piePoints.length; i++) {
- // We’re saving the reference to the div object in the point,
- // so check if it already exists
- if (piePoints[i].hintDiv == undefined) {
- // Create the div
- piePoints[i].hintDiv = document.createElement(“DIV”);
- piePoints[i].hintDiv.className = “PiePieceLabel”;
- piePoints[i].hintDiv.innerHTML = “<strong>” + piePoints[i].label + “</strong><br/>” + piePoints[i].x + ” of ” + mySeries.getTotalValue() +
- ” (” + (piePoints[i].x / mySeries.getTotalValue() * 100) + “%)”;
- document.getElementsByTagName(“body”)[0].appendChild(piePoints[i].hintDiv);
- }
- // Find the center of the piece
- var pointCoordinates = mySeries.findCenter(piePoints[i]);
- // Adjust the location of the div based on the piece center
- piePoints[i].hintDiv.style.left = pointCoordinates.x – Math.floor(piePoints[i].hintDiv.offsetWidth / 2) + “px”;
- piePoints[i].hintDiv.style.top = pointCoordinates.y – Math.floor(piePoints[i].hintDiv.offsetHeight / 2) + “px”;
- }
- }
- };
- myChart = new EJSC.Chart(“myChart1a”,
- {
- show_legend: false,
- allow_zoom: false,
- show_mouse_position: false,
- // Hide the standard hints
- show_hints: false,
- // Assign the onAfterDraw event
- onAfterDraw: doAfterDraw
- }
- );
- mySeries = new EJSC.PieSeries(
- new EJSC.ArrayDataHandler(
- [[10, “Piece 1”],[20, “Piece 2”],[45, “Piece 3″],[25,”Piece 4”]]
- )
- );
- myChart.addSeries(mySeries);
- </script>