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

Couldnt get Graph legend shown on JPG using AnyChart-nodeJS #24

Open
ChinHong-B opened this issue Feb 5, 2021 · 5 comments
Open

Couldnt get Graph legend shown on JPG using AnyChart-nodeJS #24

ChinHong-B opened this issue Feb 5, 2021 · 5 comments

Comments

@ChinHong-B
Copy link

I am trying to insert the graph legend on the a combined graph (lines and bars). It seems i cant get the legend shown in any of the graph position. My code is as follow:

var jsdom = new JSDOM('

', {runScripts: 'dangerously'});

var window = jsdom.window;

var anychart = require('anychart')(window);
var anychartExport = require('anychart-nodejs')(anychart);
var dataSet = anychart.data.set([
    ['P1', 174, 5854, 3242],
    ['P2', 197, 4171, 3171],
    ['P3', 155, 1375, 700],
    ['P4', 15, 1875, 1287],
    ['P5', 66, 2246, 1856],
    ['P6', 85, 2696, 1126],
    ['P7', 37, 1287, 987],
    ['P8', 10, 2140, 1610],
    ['P9', 44, 1603, 903],
    ['P10', 322, 1628, 928]
  ]);

  var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
  var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
  var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });


  var chart = anychart.column();
  chart.legend(true)

  chart.title('Combination of Column, Spline-Area and Spline Chart');

  var scale = anychart.scales.linear();

  chart
    .yAxis(1)
    .title('Secondary Y-Axis')
    .orientation('right')
    .scale(scale);

  var columnSeries = chart.column(secondSeriesData);
  columnSeries.name('Column');

  var splineSeries = chart.splineArea(thirdSeriesData);
  splineSeries.name('Spline');

  var lineSeries = chart.spline(firstSeriesData);
  lineSeries.name('Line').yScale(scale).stroke('2.5 #ef6c00');


  chart.container('container');
  chart.bounds(0, 0, 1024, 800);

  chart.draw();
  anychartExport.exportTo(chart, 'jpg').then(function(image) {
    fs.writeFile( localDir+"/test.jpg", image, function(fsWriteError) {
      if (fsWriteError) {
        console.log(fsWriteError);
      } else {
        console.log('Complete');
      }
    });
  }, function(generationError) {
    console.log(generationError);
  });
@Shestac92
Copy link

@ChinHong-B
Can you provide a screenshot of the resulting chart?
The code you provided renders the legend correctly, check the sample on PG.

@ChinHong-B ChinHong-B changed the title Could have Graph legend shown on JPG using AnyChart-nodeJS Couldnt get Graph legend shown on JPG using AnyChart-nodeJS Feb 5, 2021
@ChinHong-B
Copy link
Author

test

@Shestac92
Copy link

@ChinHong-B
Hm, the chart is truncated at the bottom. Is it a screenshot of the part of the chart or it's the full result of the export?

@ChinHong-B
Copy link
Author

Sorry. I was playing with the "Chart.Bound" hence it was truncated. See attached the redo version
test

@ChinHong-B
Copy link
Author

Any update on this? It that just me or it is a common problem?

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

2 participants