Add Margin and Chart header alignment in Jfree charts - charts

Greeting,
I was wondering is it possible to add some margin to Jfree charts and align the chart title to left of the chart rather than default center of the chart.
Expected Chart
Need to add a 28 px margin to all directions. TOP , BOTTOM , LEFT and RIGHT
And to make the chart title align to the left rather than center.
Chart which i am able to generate

To Add margin to Chart we can add Padding
public void addMargin(JFreeChart jChart){
RectangleInsets chartRectangle = new RectangleInsets(28F,30F,30F,30F);
//RectangleInsets chartRectangle = new RectangleInsets(TOP,LEFT,BOTTOM,RIGHT);
jChart.setPadding(chartRectangle);
}
To align the header to Left set horizontal alignment to Chart title
public void alignChartTitle(JFreeChart jChart){
jChart.getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);
}

Set value to the lowerMargin, upperMargin property of X Axis. This is kotlin code:
val dateAxis = DateAxis("Time")
dateAxis.lowerMargin = 0.05
dateAxis.lowerMargin = 0.05
And this is the result:
[]

Related

make bigger space for legend in echarts

I'm using echarts
this is my chart
this picture shows I lost some of my legends , so,how do I make bigger space for legends, is it possible to set more space for legends? or if it is possible to make my chart smaller how can I do?
I put
var option = {
grid: {
y: 30,
y2: 90,
},
y mean space before chart, y2 - after chart

Change origin position in ios-charts

Has anyone tried setting a custom origin (0,0) for ios-charts?
The default origin is at the bottom left corner, I want my origin at the top left corner, is this possible? (see images for reference)
default
what i want to achieve
You can change label position for XAxis instance object using your chartView object.
//self.chartView is the ChartView instance.
let xAxis : XAxis = self.chartView.xAxis
xAxis.labelPosition = .top
It's quite simple.
First, as another answer said, change xAxis.labelPosition = .top.
Then, set Y axis self.chartView.leftAxis.inverted = true.
That`s all!

How do I add a units label to a ILNumerics Colorbar

I would like to display the units in text for the values displayed on the colorbar. I have a colorbar added to my ILSurface and I'd like to show my units in text on the color bar along with the range.
Edit: I want to display text at the bottom of the color bar below the bottom tick just the one label.
I was able to get this to work this way
new ILColorbar()
{
Children = { new ILLabel("nm") {Position = new Vector3(.2f,.98f,0) } }
}
I have to say the Position coordinates are not very intuitive. I had to basically adjust the numbers by trial and error until it fit. I knew that the values range 0..1 so the X value was 1 at the bottom but I wanted it up from the border. And the Y value would need to be indented in some but I wasn't sure what was a good value but .2 works.
You can access the axis of ILColorbar and configure it in the usual way. Use the LabelTransformFunc on the ticks to set your own label text. You can use the default transform func and add your unit string.
Example:
var cb = scene.First<ILColorbar>();
cb.Axis.Ticks.LabelTransformFunc = (ind, val) =>
{
return ILTickCollection.DefaultLabelTransformFunc(ind, val) + "nm";
};
You can read more about the axis configuration here:
Axis Configuration
LabelTransformFunc in ApiDoc
Edit:
If only one label is needed, then add a new ILLabel object in ILColorbar group as follows:
new ILColorbar() {
new ILLabel("z(nm)") {
Position = new Vector3(0.5,1,0),
Anchor = new PointF(0.5f,0)
}
}
The ILColorbar area have the relative coordinates 0..1 over the width and the height of the color bar. So we set position x in the middle of the ILColorbar, and position y at the bottom.
The Anchor position is used as relative position in relation to the Position point.
ILLabel Documentation

Google Charts Stacked bar formatting and spacing between data

I Used this parameter to create chart image
$params['cht']= 'bvs';//Chart Type
$params['chd'] = "t:";
$params['chd'].=$finaldata;//
$params['chm']= 'N,FF0000,-1,,12|N,000000,0,,14,,c|N,000000,1,,14,,c|N,000000,2,,14,,c';
$params['chs'] = $this->getWidth().'x'.$this->getHeight();// chart size
$params['chco'] = '4d89f9,C6D9FD,FF0000';//series color
$params['chbh'] = '80,20';//bar width and space
$params['chds'] = 'a';//$min_amount.','.$max_amount;//scaling for min and max amount
$params['chxt'] ='x';//visible axis
$params['chxr'] ='0,'.$min_value.','.$max_value;
$params['chg'] ='10,20';//Grid lines background
I am creating Stacked bar chart using google Visualization api.
I want to show the data in clear and proper spacing ,Stuck from 2 days .Thank you for help.

google charts: timeline: dynamic height with scalebar position

Thanks for viewing and answering.
I am using Google Charts (TimeLine) to display information from database.
But the Google Chart reference only provide setting fix height for the chart.
Whereas I would like to change chart height based on the number of rows I get from data.
So I made the code:
var graph = $('#chart_timeLine').children()[0].children[0].children[1];
$(graph).css('height',graph.scrollHeight);
$(graph).css('overflow-y','auto');
Now the chart don't have a vertical scrollbar and I am satisfied.
But I found that the scalebar, which shows the the scale of timeline chart is missing.(It is actually hiding under the chart, instead of showing up at the bottom of the chart).
So then I changed scalebar's position to absolute and set it to the bottom of my chart.
Then it is ugly because it has a height of 200px, while the scale is at the bottom of that 200px, leaving a huge blank between my chart and the scale.
Is there a fix for that?
Thank you.
Instead of messing with the internal workings of the chart, set the height based on the number of rows of data in the DataTable:
// set a padding value to cover the height of title and axis values
var paddingHeight = 40;
// set the height to be covered by the rows
var rowHeight = data.getNumberOfRows() * 15;
// set the total chart height
var chartHeight = rowHeight + paddingHeight;
and then in the Timeline's options, set the height:
height: chartHeight
I tried the answer, but it did not work for me. The way I got it to work for me was this:
// Calculate height
var rowHeight = 41;
var chartHeight = dataTable.getNumberOfRows() * rowHeight + 50;
var options = {
height: chartHeight
}
The + 1 to the getNumberOfRows() is for the X-axis text.
$.ajax({
...
success: function(jsonData){
...
var options = {
height: (jsonData.length * 40) + 80,
timeline: { colorByRowLabel: true }
};
chart.draw(dataTable, options);
}
});
As far as I can tell its:
30px height for each bar
10px padding for each group.
60px for the Series.
So for a 9 bar Group = (30 * 9) + 10 = 280px
Chart Height = 280px + 60px
If you are Grouping Rows you will need to determine if your date ranges overlap with any others in that group.
Google does this by:
Getting the Group items IN START DATE ORDER
Creating an empty array of Group Display Rows
For each Group Item:
For each Display Row
If Item fits in Row...
Add it to existing Display Row
Next
If No existing Display row found
Add New Display Row
Next