Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting this amazing chart #313

Closed
muhdkhokhar opened this issue Jun 3, 2014 · 26 comments
Closed

Exporting this amazing chart #313

muhdkhokhar opened this issue Jun 3, 2014 · 26 comments
Labels

Comments

@muhdkhokhar
Copy link

No description provided.

@muhdkhokhar
Copy link
Author

Hi ,

C3 charts are the best available charts.I can't believe how easy is it generate any chart.

The only thing is that how do I export a chart?

Please help me with this regard.

thanks.

@muhdkhokhar muhdkhokhar reopened this Jun 3, 2014
@muhdkhokhar muhdkhokhar changed the title Makky Exporting this amazing chart Jun 3, 2014
@Rameshc3
Copy link

Rameshc3 commented Jun 4, 2014

i am also trying to export the chart to pdf or i want to convert it to image ...if anyone has an idea please help

@lblb
Copy link

lblb commented Jun 4, 2014

It's not that easy to do solely in Javascript, especially if you want to support many browser versions. If browser supports canvas (all modern browsers do), there is rather easy way. You can use canvg (https://code.google.com/p/canvg/) library, which converts SVG to canvas.
Then something like this (http://www.nihilogic.dk/labs/canvas2image/) to let user save it as image file locally. I didn't try that myself though, so I can't tell if it works reliably with C3 charts. But this is a direction to explore.

@panubear
Copy link

panubear commented Jun 5, 2014

Hi, I find this it might be useful (http://jsfiddle.net/8ypxW/3/) but I am not successful yet.
What I try is I put our C3 chart (div tag) inside original code (span tag) but the download result I get is empty image!!!
Update: http://jsfiddle.net/panubear/mGDt8/ >> The output image was produce without c3 chart.

@aendra-rininsland
Copy link
Member

I'm doing this for the C3-based chart builder I'm working on, will share my code once it's done. Agreed with @lblb's point about canvg, that's what Quartz use in their ChartBuilder. For an idea how to do this, in addition to outputting PNGs, see: https://github.com/Quartz/Chartbuilder/blob/master/js/chartbuilder.js#L295

@aendra-rininsland
Copy link
Member

Okay, gotten this working. Here's my Angular directive for doing this, much shamelessly taken from Quartz/Chartbuilder. Ignore all the Angular stuff, all the real work is done in createChartImages().

In short, here's what I needed to do:

  1. Create an empty canvas element.
  2. Take all the styles from c3.js and make them inline on most of the SVG elements, taking care to not do this to any of your data-related objects (Which are coloured via the CSS style attribute. Line 6 of c3.css will replace any data line colours set via C3 with stroke: #000 and fill: none.).
  3. Find any elements that have "hidden" for the CSS "visibility" property and set those to "display: none". This hides all of C3's unused axes.
  4. Set fill: none on all SVG data paths so they you don't get the weird bezier clipping effect.
  5. Using Canvg, generate a PNG. There's also a function to generate a SVG in my directive, using a snippet from the NYT.

Note I've only really tested this with simple series charts, it's very very possible the other chart types will have issues and will need their own specific tweaks.

Edit: Seems the "area" types totally break the PNG output, though the SVG output seems fine. Ditto with the circular charts (gauge, pie, donut), which are broken for both SVG and PNG. I've fixed it so SVG output works for all chart types, AFAIK. PNG is being a little bit more troublesome, however...

Latest edit: I've updated the Gist, it should work for all chart types now, both PNG and SVG. hoping to release LlamaCharts sometime in the next few days if anyone wants a working implementation to play with.

@yuvii
Copy link
Contributor

yuvii commented Sep 11, 2014

Hi @Aendrew

I have been working on an exporter, which supports .png, .jpeg, .gif and .pdf. please see my pull request here

However, my method is a server-side implementation that relies on phantomjs. In my opinion it would be a good idea to have a client-side exporter as well. I'd love to see your completed version

@aendra-rininsland
Copy link
Member

@yuvii Hi! I've released my project (probably should have updated this issue...), it's at times/axisJS.

You can play with it online at http://times.github.io/axisJS/

PDF is super useful, will take a look at your PR. I'm ultimately needing print formats for axisJS sometime shortly...

@yuvii
Copy link
Contributor

yuvii commented Sep 11, 2014

Oh wow, you actually went ahead and made an entire GUI for this. I just made a command line tool for exporting. Very cool, man.

@aendra-rininsland
Copy link
Member

This is kind of more a support issue at this point than anything so closing. @yuvii's CLI tool is really cool and useful, so let's direct conversation about this to his pull request, #555.

@aendra-rininsland
Copy link
Member

Anyone arriving at this, @gonsakon's implementation here does what I did with Angular, but with jQuery — might be an easier example than the one I've given!

@raj-mehta
Copy link

Hi , I am trying to convert c3 chart i.e SVG into Image but its not working.
Looks like c3.css which is external css is not getting applied.
How can we apply the external css to an SVG

@aendra-rininsland
Copy link
Member

@raj-mehta Please ask on the C3 Google Group, this is a closed issue and the lack of detail you've provided with your query makes it practically impossible to help you.

@raj-mehta
Copy link

Thanks for your revert ,
I using the following svg and used on ur sample.html but chart on the browser and converted image from canvg don't match .
distorted

@dosborn
Copy link

dosborn commented Sep 18, 2015

I'm getting the same issue as raj-mehta with the extra wide axis bars. Did you find a solution to this?

@J-1
Copy link

J-1 commented Sep 29, 2015

The issue is that only inline styles matter when doing the export. I've modified my local version of c3 to include some additional styling (like fill-opacity:0 for line graphs that show a weird black background) and the image comes out how you'd expect.

@adrianf29
Copy link

@Aendrew please tell me the source of this http://times.github.io/axisJS/#/ i need this tutorial..please help me

@annatomka
Copy link

You can add PNG exporting feature to c3 charts using my module: https://github.com/annatomka/ng-c3-export

@morales-franco
Copy link

Hi @annatomka can I use https://github.com/annatomka/ng-c3-export whith async load graphs ? My code:

app.controller("ChartController", function ($http) {
$http.get('URL').
success(function (data, status, headers, config) {
c3.generate({
bindto: "#My-chart",
data: {
type: 'pie',
columns: [
['sample', 30],
['sample2', 200]
]
}
});
}).
error(function (data, status, headers, config) {
debugger;
});

--Draws the chart correctly but no download icon

@johnmarkli
Copy link

@annatomka Great module but I'm also having trouble with async loading graphs. The download button disappears once I re-generate the graph.

@aendra-rininsland
Copy link
Member

@annatomka That is so good! I'm totally using your module next Angular project I do!

@adamrecsko
Copy link

adamrecsko commented Apr 30, 2016

@annatomka +1

@annatomka
Copy link

@morales-franco @johnmarkli I fixed the async loading issue, you can try it in the new version (0.1.5). I added some examples too.

@c5236786
Copy link

c5236786 commented May 30, 2016

@annatomka My Pie chart is coming out to be
download

what am i missing in css?
download

@mingli1015
Copy link

mingli1015 commented Oct 5, 2016

@annatomka Great module but I'm also having trouble with the browsers. It don't work on Internet Explorer your module. Can you please fix the bug? Thanks

@aendra-rininsland
Copy link
Member

Seriously here, people. If you have issues with annatomka/ng-c3-export, report them in the annatomka/ng-c3-export issue queue.

Locking thread.

@c3js c3js locked and limited conversation to collaborators Oct 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests