score:1
After much deleting parts of my example SVG image, to find when the error would go away, I found that it's the tspan
tags - once I leave them out, canvg will display text only once as intended.
score:0
<!-- Client Side Code -->
<script type="text/javascript">
window.onload = function() {
//1. Get the Highcharts Graph from the Div containing it
var chart = $('#IDOfDivContainingHighchartsGraph').highcharts();
//2. Get SVG from Hicharts Export Service
var svgString = chart.getSVGForExport();
//3. Save it client side div to manipulate the fetched string
$('#exportedSVG').html(svgString);
//4. LOGIC TO REMOVE THE DUPLICATE TSPAN TAG
var svgTSPAN_TextElement=$("#exportedSVG text");
for(i=0;i<svgTSPAN_TextElement.length;i++){
childTspanElements=$(svgTSPAN_TextElement[i]).children("tspan");
if(childTspanElements.length==2){
childTspanElements[1].remove();
}
}
//5. Get the maniupluated object as string
svgString=$("#exportedSVG svg").get(0).outerHTML;
//6. POST Maniiulated SVG string
var url= '/URL/To/Server/Side.php';
$.ajax({
type: 'POST',
data: {svgString:svgString, upload:1},
url: url,
async: false,
success: function(data){
//Nothing here
}
});
}
</script>
//Server Side Code
<?php
if(isset($_POST["upload"])){
$SVGData=$_POST["svgString"];
$locationToSaveFile = "/location/to/Save/SVGFILE.svg";
file_put_contents($locationToSaveFile, $SVGData);
exit();
}
//By the end of this code you would have created the svg file of the hicharts on the server side
?>
score:1
I just added textOutline: 'none' inside your exporting parameter and it works for me.
Codpen with solution https://codepen.io/kirill-kirs/pen/qBjNdwg
exporting: {
sourceWidth: 1000,
sourceHeight: 1000,
chartOptions: {
plotOptions: {
series: {
dataLabels: {
enabled: true,
backgroundColor: 'rgba(0, 0, 0, 0.75)',
style: {
textOutline: 'none',
color: 'white'
}
}
}
}
}
}
score:4
This question is a bit old but I also found this pretty annoying to have this double text bug in my graphs. I took a look at the code and modified it to work with tspan. I didn't really dig into it, so I don't understand all the mechanisms taking place in the library, but I noticed that for "tspan", at some point, the object created was :
- Well, an object, with a type "tspan" and a text attribute.
- And that object also contained an other object, which is the text value of the tspan (which is then the same as the previous text attribute)
So what I did is to modify the source code of the library. If you search for
// tspan
svg.Element.tspan = function(node) {
Then you just have to add this inside the function (replacing the old content) :
if ( node.nodeName == "tspan")
this.text = '' ;
else
this.text = node.value || node.text || node.textContent || '';
And that solved my problem. I hope that helps someone.
Source: stackoverflow.com
Related Query
- When using canvg to convert Highchart SVG into PNG, all text appears twice - how to solve?
- Multi-Line Title is not working when we export to PNG using CanVG - Highcharts
- Highchart : How to use images when using "General drawing"
- load data from text file into HIGHCHART graphic using PHP
- how to convert svg to png image in internet Explorer?
- How to convert php array into javascript array for Highchart JS
- In PHP , How to convert JSON into highchart supported format
- How to show all data in highchart when having less catgories?
- How to trigger legend click event on outside when using Highchart and no using JQuery
- How to style text annotation using CSS in highchart
- Highchart issue in values and Label text when using 4 axis
- How to convert long string into CSV using the export-csv plugin for HighCharts
- How to automatically download png file from highchart when the page load
- Highchart - Angular 9: How to export all charts into single pdf?
- Highchart spline Cut Off when reach to maximum scale value. How can it fixed?. I have attached may sample code on body
- How to align highchart legend when using multiple pie chart in one container?
- How to drilldown a pie highchart into multiple containers using renderTo or redraw method?
- How to format PHP into the proper string for JSON in pie chart using highchart
- Resolve Conflict When Using Highchart and Highmap together (TypeError: ma is not a function)
- Javascript Highcharts v3.0.5 - How to hide Y Axis Title when using multiple Y Axis
- How to change series legend text color in HighChart chart?
- how to get svg of highcharts using div id?
- using angular directive to draw highchart pie chart but when i am using it in success function it is not working
- Is there a way how to dynamically create a plotline in highchart when the value is lower than previous one?
- Highcharts. Add text at right side and export all into PDF
- How to set series-label to false by default and change the color of series label text in highchart
- highcharts display in my render html page which i want to convert into PDF using wkhtmltopdf in rails
- Highchart does not load data from hidden input when using .val
- How to grab correct highchart number in selectors using Selenium Webdriver with Python with several charts on the page?
- How to add php data into highchart js file in php
More Query from same tag
- Marking specific point on highchart column
- Highcharts Gantt - Set max height and scrollbar on yAxis
- How to dynamically populate Highcharts column chart with two series
- How to remove the gap between yAxis and data?
- create column chart in highcharts dynamically from json data
- Can we use rcharts to plot Grouped_Categories charts from Highcharts?
- Slider on barchart
- Show only time labels on xAxis. Highcharts
- How do i make connectors (lines connecting datalabels) of piechart in Highcharts look straight lines and not curved?
- How to import or load Dumbbell chart in react app
- Trying to get Gridster to call functions like disable but $('.gridster ul').gridster().data('gridster'); not working
- HighCharts showing wrong month
- Json string without escape characters in highcharts
- HighCharts: How to change style of bottom most x-axis grid line
- Add 2 legends in one chart
- Having trouble passing data to Highcharts
- Highcharts - making a point clickable?
- High chart date
- Highcharts how to make legends as data labels on scatter plot
- Highcharts & Angularjs: update chart from $broadcast in the main controller doesn't update the chart like a $watch would in the chart's controller
- Highcharts use legend symbol and legend parms, not scatter marker symbols - in scatter plot
- Highcharts Pie Chart turning off data label
- How to overwrite Highcharts credits default settings
- Difference between HTML5/JavaScript and jQuery based chart libraries
- Parsing a JSON object of arrays gives different results in IE9
- HighStocks Series Data format
- Average values based on date from json to array of arrays
- How to use a javascript variable in highcharts series?
- Use ajax variable in HighCharts
- how can i create threshold chart with highcharts