angular-nvd3 change in multibar chart column width - angularjs

I use angular-nvd3 library in my angular project.
I need to change column width in "multiBarChart". I tried to change on event "on-ready" but it doesn't work
onChartReady(scope, element) {
const api = scope.api;
const chart = scope.chart;
const svg = scope.svg;
var bars = svg.selectAll("rect.nv-bar");
bars.attr("width", "200");
}

You can use the below code snippet to change the width of the bar in multi bar chart.
groupSpacing property accepts a value between 0 and 1
A value of 0.1 will make the bars very wide. A value of 0.9 will make them narrow.
chart.groupSpacing(0.8); // Value must be between 0 & 1

Related

Windows From Custom Label FromPosition and ToPosition after Xaxis min and max Range setting

I am using Windows From to generate custom charts.
I have axis data from 0 to 10 with interval of 1.0
The AxisX is in default range from -1 to 11 as shown in attached image.
I want to place custom labels on Top of the chart (AxisX2), I am using FromPosition=0.5-Interval & FromPosition=0.5+Interval, this is placing the custom label aligned with bottom X axis labels.
But when i limit the X axis range to 0 to 10, then custom label is not aligned with bottom X axis labels.
What i notice is custom label position remain fixed, but after setting the range position of the Grid position of the bottom X axis changed, so the is no alignment with bottom X axis and top secondary X axis custom label. Is there any way to align top X2 axis Custom label with bottom X axis labels ?
I am attaching my code, i would highly appreciate your help here.
Screenshot of custom label setting alignemnt
class MainForm(Form):
def __init__(self):
self.InitializeComponent()
def InitializeComponent(self):
global series11
chartArea11 = System.Windows.Forms.DataVisualization.Charting.ChartArea()
ChartType11 = System.Windows.Forms.DataVisualization.Charting.SeriesChartType()
legend11 = System.Windows.Forms.DataVisualization.Charting.Legend()
series11 = System.Windows.Forms.DataVisualization.Charting.Series()
series12 = System.Windows.Forms.DataVisualization.Charting.Series()
series13 = System.Windows.Forms.DataVisualization.Charting.Series()
title1=System.Windows.Forms.DataVisualization.Charting.Title()
Marker=System.Windows.Forms.DataVisualization.Charting.MarkerStyle()
self._chart1 = System.Windows.Forms.DataVisualization.Charting.Chart()
self._chart1.BeginInit()
self.SuspendLayout()
##### Form and Chart size
Width = 800
Height = 450
Buffer = 50
self._chart1.ChartAreas.Add(chartArea11)
series11.ChartArea = "ChartArea1"
series11.Legend = "Legend1"
self._chart1.Size = System.Drawing.Size(Width-Buffer , Height-Buffer ) # Chart Area Size
self._chart1.TabIndex = 1
self._chart1.Text = "chart1"
lista=[0,1,2,3,4,5,6,7,8,9,10]
listb=[0,8.27458E-06,0.003971857,-0.009233615,-0.022420625,-0.035589211,0.096930249,0.163891257,-0.009233615,0.003971857,-0.035589211]
Time_1=[23,23,20,30,40,50,-50,-100,30,20,50]
# Chart Type
self._chart1.Series.Add(series11)
series11.ChartType=ChartType11.Line
self._chart1.Series[0].Points.DataBindXY(lista,listb)
### Secondary Axis as Lables
chartArea11.AxisX2.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.True
chartArea11.AxisX2.Title = " Temperature [\xb0 C]"
chartArea11.AxisX2.TitleFont = Font("Arial", 10)
chartArea11.AxisX2.MajorGrid.Enabled = False;
chartArea11.AxisX2.MajorTickMark.Enabled = False;
CL_0=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_1=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_2=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_3=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_4=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_5=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_6=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_7=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_8=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_9=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CL_10=System.Windows.Forms.DataVisualization.Charting.CustomLabel()
CLs=[CL_0,CL_1,CL_2,CL_3,CL_4,CL_5,CL_6,CL_7,CL_8,CL_9,CL_10]
offset=0.5
for i in range(0,self._chart1.Series[0].Points.Count):
CLs[i].Text=str(Time_1[i])
CLs[i].FromPosition=self._chart1.Series[0].Points[i].XValue - offset
CLs[i].ToPosition=self._chart1.Series[0].Points[i].XValue+offset
chartArea11.AxisX2.CustomLabels.Add(CLs[i])
chartArea11.AxisX.Minimum = 0
chartArea11.AxisX.Maximum = max(lista)
chartArea11.AxisX.Interval=1.0
chartArea11.AxisX2.IsLabelAutoFit=False
############ End secondary axis #####################
############## MainForm############
self.ClientSize = System.Drawing.Size(Width, Height+100) ### Windows Form Area Size
self.Controls.Add(self._chart1)
self.Name = "MainForm"
self.Text = "Santhosh M WB Custom Charts Demo"
self._chart1.EndInit()
self.ResumeLayout(False)
from System.Windows.Forms import Application
Application.EnableVisualStyles()
form =MainForm()
form.ShowDialog()
#Application.Run(form)
I got it. I need to set both primary and secondary X axes range and interval same to align the custom label on secondary X Axis same as primary x axis label.
chartArea11.AxisX.Minimum = 0
chartArea11.AxisX.Maximum = max(lista)
chartArea11.AxisX.Interval=1.0
chartArea11.AxisX2.Minimum = 0
chartArea11.AxisX2.Maximum = max(lista)
chartArea11.AxisX2.Interval=1.0

Data and Series label not showing on WinForm Chart control

I am having a problem getting the default WinForms Chart control to work. I have a single chart with a single area. In this area, I want to display three (3) series whose labels are on a single legend.
Each of the value arrays shown in the code below contains six (6) values.
When I run the application the chart is only showing the background with the title and the name of the FIRST series I defined, the others seem to be ignored. Also, no grid and no data points or lines are displayed. The chart is basically blank.
this.chart.SuspendLayout();
this.chart.ChartAreas.Clear();
this.chart.Series.Clear();
ChartType chartType = ChartType.Column;
// prepare the area
const string AREA_NAME = "ChartAreaBP";
ChartArea bpChartArea = new ChartArea(AREA_NAME);
bpChartArea.AxisX.LabelStyle.Format = "dd/MMM\nyyyy";
bpChartArea.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
bpChartArea.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
bpChartArea.BackColor = System.Drawing.Color.LimeGreen;
bpChartArea.BackGradientStyle = GradientStyle.DiagonalRight;
bpChartArea.Position.Auto = true;
bpChartArea.InnerPlotPosition.Auto = true;
this.chart.ChartAreas.Add(bpChartArea);
// prepare the values. X is Date/time all other 3 are BYTE/INT
var xvals = from x in items select x.TimeStamp;
var yvalsSys = from y in items select y.Systolic;
var yvalsDia = from y in items select y.Diastolic;
var yvalsRhy = from y in items select y.Rhythm;
// The first series, other 2 omitted from HERE for simplicity
const string SYS_SERIES = "Systolic";
Series sysBPSeries = new Series(SYS_SERIES, 4);
sysBPSeries.ChartType = chartType;
sysBPSeries.ChartArea = AREA_NAME;
sysBPSeries.XValueType = ChartValueType.Auto;
sysBPSeries.YValueType = ChartValueType.Date;
sysBPSeries.XAxisType = AxisType.Primary;
sysBPSeries.YAxisType = AxisType.Primary;
sysBPSeries.Enabled = true;
this.chart.Series.Add(sysBPSeries);
this.chart.Series[SYS_SERIES].Points.DataBindXY(xvals, yvalsSys);
// here the other two series are defined.
But when I run the application only the legend of the FIRST series is shown even though the other two are defined in the code (I omitted them from this listing) just the same way as the first series.
And as I stated above, no grid nor values are shown. However, the chart shown in design mode does show all three labels on the first and only legend and all three lines.

ExtJs dynamically set axes maximum value

I would like to dynamically change the axis maximum limit of an ExtJS 4.x chart.
I tried using a listener beforerefresh but this has no effect:
var chart = Ext.create('Ext.chart.Chart', {
...
listeners: {
beforerefresh(me, eOpts)
{
// set y-axes to max(raw_value)
console.log('before refresh');
// set maximum axis value of Y axis to 0.1
me.axes.getAt(1).maximum = 0.1;
}
},
The code is reached, but using me.axes does not seem to have any effect at all.
What is the correct way to do it?
Thanks

how to display an image with the grid.lua lib

i have found this lib for easily create a grid in lua but i can't assign an image on each cells.
https://github.com/CoderDojoSV/corona-game-template/blob/master/docs/grid.md
I have contacted the author of the grid.lua but no answer anymore.
Do you have the true syntax ? thanks for your help.
local grid = require("grid")
myGrid = grid.newGrid(5, 5, 500)
myGrid:eachSquare(function(doeach)
From what I see in documentation grid is based on rectangle objects, so you won't be able to assging image to grid directly.
But you can put image in each squares coordinates
Base on docs:
local myGrid = grid.newGrid(8, 8, 700)
myGrid:eachSquare(function(gridSquare)
local image = display.newImage(pathToYourImage)
image.x, image.y = gridSquare.displayObject.x, gridSquare.displayObject.y
end)
If you need reference in grid squares to image you can assign it to gridSquare
gridSquare.myImage = image
That way in every further eachSquare iteration you will have access to image reference.
i have found the solution
grille:eachSquare(function(gridSquare)
gridSquare.displayObject:setFillColor(0, 0, 0, 255)
gridSquare.displayObject.xScale=.1
gridSquare.displayObject.yScale=1
gridSquare.myImage = display.newImage("my2.png")
gridSquare.myImage.x = gridSquare.displayObject.x+35
gridSquare.myImage.y = gridSquare.displayObject.y
gridSquare.myImage.yScale=0.5
gridSquare.myImage.xScale=0.5
end)

ext js 4 column chart bug? series remain visible when I hide them

Feeling I had not enough control over the chart if I had used a grouped column chart, I made my own version by just adding different series to the chart. After all the store, the number of series, their colors and such all need to be set dynamically and not hard coded. So basically this is what I have:
chart = Ext.create("Ext.chart.Chart", {
store: dataStore,
axes: dynamicAxes,
series: series
});
I leave out the not interesting stuff such as width, height of the chart etc.
now I have a method whichs returns a series object. This is added to the series array mentioned in the code above. The function has a "item" object parameter and also an idx param which is the index of the item object from the array it comes from, and a max param which is the size of the item array
the function returns something like this:
var w = (typeof (max) !== "undefined" && max !== null) ? this._getWidthByMax(max) : 30;
return {
type: "column",
axis = "left",
xField = "timestamp",
yField = item.id, // store field name equals the id of the item object
style = { stroke: colorCode, "stroke-width": (item.isDefault) ? 2 : 1, fill: colorCode },
width = w,
renderer = function (sprite, rec, attr, bix) {
var nx = idx * w;
return Ext.apply(attr, { translation: { x: nx} });
}
}
now this works fine for the number of columns I want to have. That can be one, two, three... up to seven currently.
However, if I want to hide a series, the following call doesn't work:
chart.series.getAt(idx).hideAll();
while it does work if I render my chart as a line chart.
is this a bug in Ext-js 4 or is it because of how I rendered the series for my column chart?
since nobody has replied to my question and I have found a solution in the meantime, I might as well answer my own question...
the problem occurred in Ext Js 4.0.7.
With version 4.1 RC 2 the hideAll behaved correctly.
So the solution, for anyone who would have the same problem, is to upgrade to 4.1 RC 2 or newer.

Resources