How to create dynamic charts in a power point by using Aspose slides - aspose-slides

Need help for creating dynamic charts in a power point by using Aspose slides.

#Mohini,
I have observed your requirements and like to share that Aspose.Slides offers you to create MSO charts programmatically. I suggest you to please try using following sample code to create a Clustered Column chart.
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.Slides[0];
// Add chart with default data
IChart chart = sld.Shapes.AddChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
// Setting chart Title
// Chart.ChartTitle.TextFrameForOverriding.Text = "Sample Title";
chart.ChartTitle.AddTextFrameForOverriding("Sample Title");
chart.ChartTitle.TextFrameForOverriding.TextFrameFormat.CenterText = NullableBool.True;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;
// Set first series to Show Values
chart.ChartData.Series[0].Labels.DefaultDataLabelFormat.ShowValue = true;
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;
// Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
// Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);
// Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
// Take first chart series
IChartSeries series = chart.ChartData.Series[0];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
// Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Red;
// Take second chart series
series = chart.ChartData.Series[1];
// Now populating series data
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.DataPoints.AddDataPointForBarSeries(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
// Setting fill color for series
series.Format.Fill.FillType = FillType.Solid;
series.Format.Fill.SolidFillColor.Color = Color.Green;
// First label will be show Category name
IDataLabel lbl = series.DataPoints[0].Label;
lbl.DataLabelFormat.ShowCategoryName = true;
lbl = series.DataPoints[1].Label;
lbl.DataLabelFormat.ShowSeriesName = true;
// Show value for third label
lbl = series.DataPoints[2].Label;
lbl.DataLabelFormat.ShowValue = true;
lbl.DataLabelFormat.ShowSeriesName = true;
lbl.DataLabelFormat.Separator = "/";
// Save presentation with chart
pres.Save(dataDir + "AsposeChart_out.pptx", SaveFormat.Pptx);
I am working as Support developer/ Evangelist at Aspose.
Many Thanks,

Related

Add padding to the right of the down arrow in a picker in ios renderer

I am adding a down arrow to the xamarin picker. I created a custom iOS renderer for this. I can get the arrow to show up fine, but it is touching the right hand side of the picker. How can I add some padding to the right of the arrow? I have tried the following in my ios renderer.
protected void UpdateBackground(UITextField control)
{
if (control == null) return;
control.Layer.CornerRadius = ElementV2.CornerRadius;
control.Layer.BorderWidth = ElementV2.BorderThickness;
control.Layer.BorderColor = ElementV2.BorderColor.ToCGColor();
var downArrowLabel = new UILabel(new CoreGraphics.CGRect(new CoreGraphics.CGPoint(control.Frame.Size.Width - 20 - 16, 0), new CoreGraphics.CGSize(20, control.Frame.Size.Height)));
downArrowLabel.Font = UIFont.FromName("FontAwesome", 30);
downArrowLabel.Text = "\uf0d7";
downArrowLabel.TextColor = UIColor.Black;
downArrowLabel.TextAlignment = UITextAlignment.Center;
downArrowLabel.ContentMode = UIViewContentMode.ScaleAspectFit;
control.RightView = downArrowLabel;
control.RightViewMode = UITextFieldViewMode.Always;
control.RightView.Bounds = new CoreGraphics.CGRect(0, 0, 20 + 16, control.Frame.Size.Height);
}
I wrote a Picker renderer based on your code and tested it. I found that adding a few spaces after the Text can effectively solve this problem. It looks strange, but it works, like this
downArrowLabel.Text = "\uf0d7 ";

Animated appearance of Photoshop layers

I'm working with a Photoshop document that has over 1,000 layers in it (1052, to be precise). The file itself is a collage and each layer is an individual image within that collage. So, when all layers are visible it's a complex collage of 1052 overlapping images. What I have been trying to do is create an animation of the collage assembly so that, for instance, layer 0 appears and then layer 1, layer 2, etc. and when each layer appears the previous layer also stays visible.
I have been able to make a frame animation, to which I've then added all other layers as frames but in this case the animation I create just makes each new frame/layer visible on its own, and making the previous layer(s) invisible. I've gone through the first several frames, manually keeping the previous layer/frame visible but I'm hoping there's a way to do this more automatically.
Is there an approach or a setting I'm missing that will allow me to automagically create this animation, keeping each frame visible as the next frame also becomes visible?
Basically, the premise of want you want is to go through all layers, switching on and off the viability as you go. Or switch them all off before you start, and get the code to loop through all the layers. Also as you are starting out, get rid of any groups, it'll just be easier. Make a copy of the psd without them if you have to.
In Photoshop scripting, the top most layer is 0. The next one below is 1 etc. It's easier to count backwards over the loop
for (var i = numOfLayers -1; i >= 0; i--)
{
// do stuff here
}
The visibility of each layer is controlled with:
theLayer.visible = true; // visible
thatLayer.visible = false; // not visible
So in short you'll have something like this:
// WITH ALL THE LAYERS VISIBILITY SWITCHED OFF TO START WITH!
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
// call the source document
var srcDoc = app.activeDocument;
// get the number of layers in the PSD
var numOfLayers = srcDoc.layers.length;
var myFolder = "D:\\temp\\";
// main loop
// ignore background
for (var i = numOfLayers -2; i >= 0 ; i--)
{
var docName = "image_" + i + ".jpg";
// get a reference to the layers as you go up
var thisLayer = srcDoc.layers[i];
thisLayer.visible = true;
// duplicate image into new document
duplicate_it(docName);
// active document is now the NEW one!
// flatten it
activeDocument.flatten();
jpeg_it(myFolder + docName, 12);
// close the image WITHOUT saving as we've just saved it
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// make the source document the active document
app.activeDocument = srcDoc;
// switch OFF the layer
thisLayer.visible = false;
}
// function DUPLICATE IT (str)
// --------------------------------------------------------
function duplicate_it(str)
{
// duplicate image into new document
if (arguments.length == 0) str = "temp";
var id428 = charIDToTypeID( "Dplc" );
var desc92 = new ActionDescriptor();
var id429 = charIDToTypeID( "null" );
var ref27 = new ActionReference();
var id430 = charIDToTypeID( "Dcmn" );
var id431 = charIDToTypeID( "Ordn" );
var id432 = charIDToTypeID( "Frst" );
ref27.putEnumerated( id430, id431, id432 );
desc92.putReference( id429, ref27 );
var id433 = charIDToTypeID( "Nm " );
desc92.putString( id433, str ); // name
executeAction( id428, desc92, DialogModes.NO );
}
// function JPEG IT (file path + file name, jpeg quality)
// ----------------------------------------------------------------
function jpeg_it(filePath, jpgQuality)
{
if(! jpgQuality) jpgQuality = 12;
// jpg file options
var jpgFile = new File(filePath);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpgQuality;
activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}

Trying to set custom colours for a chart

I'm trying to add custom colours to a column chart, so each column has a different colour. I have the following code:
__this._chartColours = ['#2776BD', '#00A1D0','#00C195','#7ED321','#A8C600','#C9B600','#E3A600', '#F7941E', '#FC7149'];
__this._chart = am4core.create(__this._tileChartDiv[0], am4charts.XYChart);
if(result.chartDataMap != null)
{
var colorSet = new am4core.ColorSet();
var counter = 0;
$.each(result.chartDataMap, function(xAxis, yAxis)
{
__this._dataProvider.push({"category": xAxis, "column-1": yAxis});
__this._chart.colors.list.push(am4core.color(__this._chartColours[counter]));
});
__this._chart.data = __this._dataProvider;
__this._chart.padding(40, 40, 40, 40);
var categoryAxis = __this._chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.minGridDistance = 60;
categoryAxis.title.text = result.xAxisTitle;
var label = categoryAxis.renderer.labels.template;
label.wrap = true;
label.maxWidth = 120;
var valueAxis = __this._chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.title.text = result.yAxisTitle;
var series = __this._chart.series.push(new am4charts.ColumnSeries());
series.dataFields.categoryX = "category";
series.dataFields.valueY = "column-1";
series.tooltipText = "{valueY.value}"
series.columns.template.strokeOpacity = 0;
__this._chart.cursor = new am4charts.XYCursor();
}
It renders the chart fine based on the dataprovider I create but it is not setting the colors. I got the colours code from here: https://www.amcharts.com/docs/v4/concepts/colors/. The XY Chart and derivative charts section
I tried to use a theme, but that didn't work either:
function am4themes_myTheme(target)
{
if (target instanceof am4core.ColorSet)
{
$.each(__this._chartColours, function(index, item)
{
target.list.push(am4core.color(item));
});
}
}
am4core.useTheme(am4themes_myTheme);
It sets all the columns to the first colour. Then I tried adding a color property to the dataProvider for each column but again it sets them all to have the first colour.
I'm pretty much out of ideas.
There are a few issues here.
First, if you want the chart to use only your colors, instead of appending to the default chart's ColorSet, you have to manually override it by assigning an array of Colors to chart.colors.list (instead of pushing values to it).
Next, the column's color (fill) by default is based on its series. So even if you populate the chart's ColorSet, it's only each new series that will get a different color, not each column.
To set an individual column's color it would be something like:
column.fill = am4core.color("#2776BD");
To get each column to have its own color, we can set that upon the column's first instantiation, i.e. on its template's inited event. Further, a column's dataItem will have a property/reference to its index, so we can use that with ColorSet's getIndex method to assign colors in sequence.
So your final code might look something like this:
__this._chart.colors.list = [
am4core.color("#2776BD"),
am4core.color("#00A1D0"),
am4core.color("#00C195"),
am4core.color("#7ED321"),
am4core.color("#A8C600"),
am4core.color("#C9B600"),
am4core.color("#E3A600"),
am4core.color("#F7941E"),
am4core.color("#FC7149")
];
series.columns.template.events.once("inited", function(event){
event.target.fill = chart.colors.getIndex(event.target.dataItem.index);
});
Here's a fork of our Simple Column Chart demo with the above code and your custom colors:
https://codepen.io/team/amcharts/pen/2ef06f392b347412c61bcdcd3439a5c6

AM Charts initial view using zoomToDates

Been stumped on this for a little bit.
I found some other help on zoomToIndexes, but I cant get the zoomToDates to work on my page.
Live page is
b2 resource urq sales
Im trying to set the initial view to show from 2000 to current.. I want to slap some original sales data from early 80's in the graph, but dont want the graph to initially show the last 30+ years..
Any help would be MUCH appreciated!
zoomToDates takes real JavaScript Date objects as parameters:
chart.zoomToDates(new Date(2005, 0, 1), new Date(2015, 11, 31));
You can use chart's rendered event to "pre-zoom" on load as well:
var chart = AmCharts.makeChart("chartdiv", {
// your chart config
// ...
});
chart.addListener("rendered", function(event) {
event.chart.zoomToDates(new Date(2005, 0, 1), new Date(2015, 11, 31));
});
Note, that months in Date() constructor parameter (second parameter) are zero-based. Meaning January is 0, February - 1, etc.
You should use valueAxis property of chart object for zoomToValues. I hope this might help you.
var chart= AmCharts.makeChart("chartdiv", {
"type": "gantt",
"theme": "black",
...
});
zoomChart();
chart.addListener("dataUpdated", zoomChart);
function zoomChart(event) {
chart.valueAxis.zoomToValues(new Date(2017, 2, 10), new Date(2017,2,12));
// or ==> event.chart.valueAxis.zoomToValues(new Date(2017, 2, 10), new Date(2017,2,12));
}
This worked for me.:
var chart = AmCharts.makeChart('chartdiv', {
type: 'serial',
...
});
chart.addListener('dataUpdated', zoomChart);
zoomChart();
function zoomChart() {
chart.zoomToDates(new Date(2018, 2, 26), new Date(2018, 2, 28));
}
Note: The months parameter in Date() constructor are zero-based. January is 0, February is 1 and etc.

Dhtmlxwindow attachURL issue

I have created a dhtmlxwindow object and loaded a jsp page using attachURL.
dhxwindow.attachURL('myPage.jsp');
and in myPage.jsp ,
i have created a layout object.
var mylayout = new dhtmlxLayoutObject(document.body, '3u');
toolbar = mylayout.cells('a').attachToolbar();
toolbar.addButton("Validate", 0, "", "images/queryValidation24.png", "images/queryValidation24.png");
toolbar.addButton("Preview", 1, "", "images/previewBtn24.png", "images/previewBtn24.png");
toolbar.setAlign('right');
//and i have other dhtmlxcomponents in other cells
Problem is i am unable to view the toolbar.
What will be the problem?
First of all you need to use correct syntax as CAPITAL letters:
var mylayout = new dhtmlXLayoutObject(document.body, '3U');
Main page:
dhxWins = new dhtmlXWindows();
dhxWins.enableAutoViewport(false);
dhxWins.attachViewportTo(document.body);
dhxWins.setImagePath("../dhtmlxWindows/codebase/imgs/");
w1 = dhxWins.createWindow("w1", 100, 100, 500, 500);
w1.attachURL("layout_toolbar_test.html");
Attached page:
var mylayout = new dhtmlXLayoutObject(document.body, '3U');
toolbar = mylayout.cells('a').attachToolbar();
toolbar.addButton("Validate", 0, "", "images/queryValidation24.png", "images/queryValidation24.png");
toolbar.addButton("Preview", 1, "", "images/previewBtn24.png", "images/previewBtn24.png");
toolbar.setAlign('right');
Result (sorry, haven't your image files):

Resources