Excel - two graphs in one (side by side) - excel

I have two graphs in Excel, but I want to merge the charts into one graph. As you can see, I have reduced the size of the chart in graph1 and I want to move the chart in the graph2 into the empty space in graph1

I think there are many ways to do this in basic excel like jrichall showed you but If you are willing to use an excel add-in to create this double chart, you could try FunFun.
It allow you to code javascript in excel, merging two charts in one is pretty easy in programming languages such as javascript.
Here is a working code I have written for you:
https://www.funfun.io/1/#/edit/5a3d0933b848f771fbcdec96
As you can see, I use a Json file to acquire the data used in the spreadsheet. Once the data is "stored", I can use it with javascript and create my charts.
I use Chart.js library to create those two charts, I basically copied this code twice to get two chart (I just changed the data and the word "bar" by "line"):
var barChart = new Chart(ctx, {
type: "bar",
data: {
// x axis represented by labels
labels: [1, 2, 3, 4, 5, 6],
datasets: dataset
},
options: {
legend: {
display: false
},
scales: {
yAxes: [
{
ticks: {
min: 0,
max: 10
}
}
]
}
},
animation: false
});
The documentation of Chart.js is pretty good and has a lot of examples for different type of charts.
Once you are satisfied with your chart, you can load it in excel by pasting the URL in the Funfun add-in. Here is how it looks like:
I used a css file to correctly align the title (.label).
Disclosure : I’m a developer of funfun

I think a little more info would help. How is your data set up? Are you using pivot tables / pivot charts? I think I can help once I get a better idea of where your data is coming from and how you have it set up.
Edit to add example of how I work with charts:
Multi-graph chart
Second Edit:
Multi Chart 2

Unless I missed something above, I think that we can make this a bit simpler by editing your chart as follows:
Select Chart Tools in the ribbon
Select 'Change Chart Type` icon
Select Combo (last option)
Change one of the axes to be a Secondary axis and change type to Line instead of Bar.

Related

Changing table column width using Google-Slide-API and python

I have a Spreadsheet document and by using Google-Sheet-API I'm fetching the data from it. Then by using Google-Slide-API I'm creating a Slide document with 'n' slides. On each slide I'm creating a 2-column table with 'n' rows. Every first column on every slide always contains data from the Spreadsheet's A column. The second columns contain data from the other Spreadsheet's columns (from B to 'n'). Then I'm changing the text size. So far so good.
Now, when I try to adjust the columns width of each table on each slide it doesn't do anything which is an issue because some tables contain more information and therefore the tables don't fit the slide. This is the part of the code that doesn't work:
for i in range(number_of_slides):
regs = [
{'updateTableColumnProperties': {
'objectId': tableID[i],
'columnIndices': [j],
'tableColumnProperties': {
'columnWidth': {'magnitude': mag[j], 'unit': 'PT'}
},
'fields': 'columnWidth'
}
} for j in range(2) ]
SLIDES.presentations().batchUpdate(body={'requests': reqs},
presentationId=deckID).execute()
The tables always remain the same with or without this part so it doesn't have any affect whatsoever. The code doesn't return any errors or messages.
I believe your goal as follows.
You have a Google Slides.
The Google Slides has the several slides, each slide has a table which has 2 columns.
You want to change the column width of 2 columns.
You want to achieve this using googleapis for python.
You have already been able to use the batchUpdate method using Google Slides API.
Modification points:
I think that your request body is correct. But, I would like to propose one modification point. In your script, batchUpdate method is used in a loop. I think that when batchUpdate is used, updateTableColumnProperties for all slides in a Google Slides can be run by one API call.
Although I'm not sure about your values of mag and your whole script, as a sample script for achieving your above goal, how about the following modified script? If this helped you to understand Slides API, I'm glad.
Modified script:
About creds, please use your authorization script. Also, you can see it at Quickstart for python.
service = build('slides', 'v1', credentials=creds)
PRESENTATION_ID = '###' # Please set Google Slides ID.
magnitude = [100, 300] # Please set the widths for the columns A and B in each table. In this sample, 100 and 300 PT are set.
# 1. Retrieve an object for each slides.
presentation = service.presentations().get(presentationId=PRESENTATION_ID).execute()
# 2. Create a request body for the batchUpdate method.
slides = presentation.get('slides')
requests = []
for slide in slides:
pe = slide.get('pageElements')
if pe:
for pageElement in pe:
t = pageElement.get('table')
if t:
for i, m in enumerate(magnitude):
requests.append({
'updateTableColumnProperties': {
'objectId': pageElement['objectId'],
'columnIndices': [i],
'tableColumnProperties': {
'columnWidth': {'magnitude': m, 'unit': 'PT'}
},
'fields': 'columnWidth'
}
})
# 3. Request the request body.
service.presentations().batchUpdate(body={'requests': requests}, presentationId=PRESENTATION_ID).execute()
Note:
When above script is run, the widths of columns "A" and "B" of the table in each slide are modified. In this sample script, 100 and 300 PT are set for the columns "A" and "B", respectively. About this, please modify for your actual situation.
References:
Method: presentations.get
Method: presentations.batchUpdate
UpdateTableColumnPropertiesRequest

How To change Color in pie chart with the using of pykcharts library?

I Need 10 different Colors in Pie chart Using the Library of pykcharts.
Is it possible Because As per the Documentation they Provide only one shade_color.
Go through this link http://pykcharts.com/tour/pie
#Tkingovr chart_color is for all charts but One dimensional. You can use shade_color for One dimensional charts https://github.com/pykih/PykCharts.js/wiki/Colors#shade-color
#KIRANJOSHI
var selector = "pieContainer", // selector of your chart
colors = ["red","blue","green","yellow","orange"];
setTimeout(function() {
d3.selectAll("#" + selector + "_svg path.pie")
.attr("fill",function(d, i) {
return colors[i];
});
},1000);
setTimeout is required since the chart may take time to render and there is no provision in the current version to run a piece of code on chart render complete.
According to the documentation you should be able to pass in values like this:
{
"chart_color": ["blue","green","Yellow"]
}
The chart also accepts any of the following:
Color Names (Eg: "red")
Hex values (Eg: "#B0171F")
RGB values (Eg: "rgb(176,23,31)" )

Display custom tool tip in Jqplot Line chart?

For example I have plotted a line chart based on the date and number of students registered on a particular day on x and y axis respectively. When i mouse over to a particular point in the line chart i can view the tool tip displaying the x and y axis values. Instead I want to display the names of the students registered on that day when I mouse over to a particular point. Is there any solution for this problem? If there is no work around with Jqplot, please suggest me any other charts.. Please help me out. Thanks in advance.
Here's a little example I put together for you.
It uses the largely undocumented tooltipContentEditor property of the highlighter plugin:
highlighter: {
show: true,
sizeAdjust: 7.5,
tooltipContentEditor:tooltipContentEditor
}
Where your data is predefined like:
var students = [
['Bob','Mark','Dave'],
['Tim','Mike']
];
var data = [students[0].length,students[1].length];
function tooltipContentEditor(str, seriesIndex, pointIndex, plot) {
// display series_label, x-axis_tick, y-axis value
return students[pointIndex].join(", ");
}

How do I tell FLOT to NOT use 0 as the default minimum for the Y axis in a bar chart?

I am using the FLOT charting library to plot calories consumed over time. I would like the y-axis to use autoscaling (to just show values that are +/- the min and max in the dataset).
However, the chart always uses 0 as the minimum for my bar chart rather than autoscaling the y-axis values. Here is my code:
function DrawCalorieChart(calorieData) {
plot = $.plot($("#CalorieHistoryChart"), [calorieData],
{
series: {
bars: { show: true, barWidth: 0.8, align: "center" }
},
legend: {
show: false
},
xaxis: { tickDecimals: 0, tickSize: 1, mode: "categories", tickLength: 0 },
yaxis: { autoscaleMargin: 0.025 },
grid: { labelMargin: 10 }
});
}
I can manually set a minimum value but the problem is that I don't know what the minimum might be after new data is entered. I have tried removing the yaxis spec altogether, setting an autoscaleMargin (as shown) and setting the min to null. But nothing works - the minimum is either a static value or zero! Any help would be greatly appreciated.
Currently there's no way to do this within the library's own API. You'll need to write some JS to iterate over your values and find a min/max manually. This could be done either outside your plot/redraw calls, or in a processRawData hook, which might work better if you're constantly adding values and redrawing.
Addressing this is actually an active project that I expect will be merged into the Github master branch within the next 2-3 weeks. So depending on whether you're able to wait, and willing to use less-stable code, that's another option.
Current answer after the change mentioned in DNS' answer has been implemented:
Set zero: false in the bar options.
From the official documentation:
Area and bar charts normally start from zero, regardless of the data's range. This is because they convey information through size, and starting from a different value would distort their meaning. In cases where the fill is purely for decorative purposes, however, "zero" allows you to override this behavior. It defaults to true for filled lines and bars; setting it to false tells the series to use the same automatic scaling as an un-filled line.

Flot pie charts - externally selecting slices

I found this solution.
If type of chart is pie, how specify parameters (x,y) of highlight(x, y)?
Thanks
Sorry for my bad English.
Unfortunately, flot doesn't expose the pie highlighting code to the user. So we are pretty much out of luck, but what may work for you is synthesizing a click event at the appropriate place on the page:
$("#highligher").click(function () {
var e = jQuery.Event('click');
e.pageX = 250; //add a made up x/y coordinate to the click event
e.pageY = 250;
$('#plot canvas:first').trigger(e); //trigger the click event on the canvas
});
Here it is in action: http://jsfiddle.net/ryleyb/mHJm5/
The problem is you have to know where the slice you want to highlight is already. This would be easy enough to set if the graph is static. If it's a dynamic graph, you'd have to dig into the source of the pie code to figure out how to calculate where the pie slice is. It might be easier in that case to just have a copy of all the pie functions and manually draw on the pie overlay.
Just got this working by altering a few things...
I changed highlight and unhighlight in jquery.flot.pie.js to pieHighlight and pieUnhighlight.
Then, after these two lines in jquery.flot.pie.js...
plot.hooks.processOptions.push(function(plot, options) {
if (options.series.pie.show) {
I added...
plot.highlight = pieHighlight;
plot.unhighlight = pieUnhighlight;
We're maintaining selection state outside of the chart (as a backbone model). When a selection event (click) occurs, we set the selected slice in the model. When selection changes, we refresh the chart using a selection color for the pie slices that are selected.
var data = [];
var color = slice.index == selected ? '#FF0000' : '#0000FF';
data.push({label:slice.Label,data:slice.Value,color:color});
The snippet above uses blue for all non-selected slices, red for the selected slice. Your color logic will be more sophisticated.
NOTE: You can also use rgba CSS for the colors, which gives a really nice effect. For example:
var color = slice.index == selected ? 'rgba(0,0,255,1)' : 'rgba(0,0,255,0.5)';

Resources