How to create a chart?

Hi I am evaluating Aspose.Excel. I’d like to create a chart that
draws data point through API. For instance, a pseudo code like:

Chart chart = excel.worksheet[0].charts.add();
ASeries series = chart.NSeries.Add();
DataPoint point1 = new DataPoint(X, Y);
series.add(point1);

Could someone show me an example?

Please check

for reference.

Reference page shows how to setup a chart. But I want to know the way
to add datapoints through API

When you add the source data to the chart, the datapoints are automatically generated.

The example only shows add data from columns. But the data I need to
draw on the chart is consolidated from the columns. Do you have example
for that?

Please create an Excel file with chart to show your need. Then I can provide related sample code.

ok, for example, if I have a column contains the following data

0
1
0
3
2
0

I need to create a chart to display there are 3 zeros, 1 one, 1 two and 1 three.
So, the Y axis is the count, X axis is value (0, 1, 2, 3)

thanks,

Still not sure about what kind of chart you want to create. Please manually create it in MS Excel. Then I can provide sample code to create it.

the attached is the chart I want to create

Thanks

Please try the following sample code with the attached fix:

Excel excel = new Excel();

int chartIndex = excel.Worksheets[0].Charts.Add(ChartType.Scatter, 10, 3, 25, 10);
Chart chart = excel.Worksheets[0].Charts[chartIndex];
chart.NSeries.Add("{15}", true);
chart.NSeries.Add("{17}", true);
chart.NSeries.Add("{2}", true);

chart.NSeries[0].Name = "coupon 0";
chart.NSeries[1].Name = "coupon 1";
chart.NSeries[2].Name = "coupon 2";

chart.NSeries[0].XValues = "{0}";
chart.NSeries[1].XValues = "{1}";
chart.NSeries[2].XValues = "{2}";

excel.Save("d:\\test\\abc.xls");

@rwang,

Aspose.Excel has been changed to Aspose.Cells now. Aspose.Cells does support to create all standard and advanced MS Excel charts. It also supports to render the chart to image or PDF format. See the following sample code for your reference:
e.g.
Sample code:

// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection
Worksheet worksheet = workbook.Worksheets[sheetIndex];

// Adding sample values to cells
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);

// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);

// Create an instance of ImageOrPrintOptions and set a few properties
ImageOrPrintOptions options = new ImageOrPrintOptions()
{
    VerticalResolution = 300,
    HorizontalResolution = 300,
    SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
};
// Convert chart to image with additional settings
chart.ToImage("chartPNG_out.png", options);

See the document for your further reference:

You may also download the up-to-date examples/demos here.