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

Support writing the HTML to a file #16

Open
jerrypnz opened this issue Jul 3, 2017 · 11 comments
Open

Support writing the HTML to a file #16

jerrypnz opened this issue Jul 3, 2017 · 11 comments

Comments

@jerrypnz
Copy link

jerrypnz commented Jul 3, 2017

Maybe introduce an command line option -o or something like that, which is followed by a file path for writing the chart to. It can be super useful for generating a lot of charts using scripts.

@marianogappa
Copy link
Owner

I've been keen to do this myself as well. A few considerations:

  • Do we not need some additional modifier to just return the current supported source code of Chart.js? The chart code alone will not work without the library, and while the user is free to include it himself it'd be better to have a supported version output by chart itself.
  • What exactly should be returned by chart? I'd go for <div></div><script>...</script> tags, the div containing the canvas and the script containing the data.

@jprobichaud
Copy link

I think what we're looking at is a way to save it as an image directly.

@marianogappa
Copy link
Owner

@jprobichaud that's an interesting use case. We've had a one-on-one chat with @moonranger a few months ago and his use case was a throw-away dashboard. Think of it as a poor man's Grafana.
Btw, I've convinced @Kuraio to write the code for this feature soon.

@jprobichaud
Copy link

Thanks a lot, this is very appreciated!

@szaydel
Copy link

szaydel commented Nov 7, 2017

@jprobichaud, I would argue that saving directly as an image in some ways puts requirements at odds with chart, because the library has only minimal support, as far as I know, in its API for binary encoding to a PNG format. It is not that it is wrong tool for the job, just that perhaps as currently implemented it is not very suitable. Certainly even less suitable if you wanted to export to say PDF.

@jprobichaud
Copy link

I see. Currently, I'm using chart from the command line to generate simple charts to add to wiki pages. I simply right-click on the canvas in the web browser and do "save image" and get the png out (then go through imagemagick to change the transparent background into a solid white background). It's all good, but it would be nice of we could do that in shot.

The simplicity of the interface compared to more powerful tools like gnuplot is appealing but the lack of automation to get the non-dynamic "picture" of the graph is a limiting factor.

@marianogappa
Copy link
Owner

@jprobichaud: I'm afraid @szaydel is right about the complexity of adding this image export feature: chart outputs HTML/JS and relies on ChartJS for actually drawing the chart; adding image export would require an entirely separate output framework that would need to be feature-by-feature compatible with ChartJS. It's probably not happening.

You could try this instead, though: https://medium.com/@dschnr/using-headless-chrome-as-an-automated-screenshot-tool-4b07dffba79a
I'm sure you can automate your screenshots. You can also batch resize if the screenshot doesn't provide this feature.

@szaydel
Copy link

szaydel commented Nov 7, 2017

I think realistically unless folks maintaining Chart.js add more robust support to export image data, adding that to chart is probably not a good idea. You are likely going to have to substantially add to complexity while also dealing with new cross-compatibility issues and such.

@jprobichaud
Copy link

Agreed, I understand the concerns. I guess then the original intent of this ticket to have the ability to specify the output filename (instead of a random tmp filename) would still be of actuality.

@szaydel
Copy link

szaydel commented Nov 15, 2017

@jprobichaud: If you are still looking, I pushed a small changeset, which admittedly can use some refinement, with support for writing files to a given path. There is a -filename option, which, given a valid path, i.e. directory needs to exist, and if file exists it will be overwritten, chart data will be placed into the file identified by the path.

$ chart -filename '/some/known/existing/location/mychart.html'

You should be able to grab the code here and build it identically to how you build code form this repository. Branch with changeset

Let me know if this works for you. I hope it is at least in the ballpark.

@TonyStark
Copy link

@szaydel Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants