I am using ChartJsLineChart in ChartJs.Blazor nuget, and I am stuck at sending data to ChartJsLineChart.
All the examples including this one
http://blazorhelpwebsite.com/Blog/tabid/61/EntryId/4363/Adding-Charts-To-Server-Side-Blazor-Using-ChartJs-Blazor.aspx
uses TimeTuple as a way to add data to dataset
_WeightDataSet = new LineDataset<TimeTuple<int>>
{
BackgroundColor = ColorUtil.FromDrawingColor(System.Drawing.Color.White),
BorderColor = ColorUtil.FromDrawingColor(System.Drawing.Color.Red),
Label = "Weight per Day",
Fill = false,
BorderWidth = 2,
PointRadius = 2,
PointBorderWidth = 2,
SteppedLine = SteppedLine.False,
Hidden = false
};
I am wondering what would be an alternative to TimeTuple. I tried using Tuple but that resulted with a blank chart ie. no YValues where not recognized.
You can use any reference type supported by ChartJs.Blazor to add data to the chart. I identified 3 main categories of types of data that are used with line charts.
1) If you simply want to use a (double/int) value type along both x-axis and y-axis then you can use the ChartJs.Blazor.ChartJS.Common.Point data type. For e.g.
_WeightDataSet = new LineDataset<ChartJs.Blazor.ChartJS.Common.Point>
{
BackgroundColor = ColorUtil.FromDrawingColor(System.Drawing.Color.White),
BorderColor = ColorUtil.FromDrawingColor(System.Drawing.Color.Red),
Label = "Weight per Day",
Fill = false,
BorderWidth = 2,
PointRadius = 2,
PointBorderWidth = 2,
SteppedLine = SteppedLine.False,
Hidden = false
};
You might also have to configure the xAxes in the config to a LinearCartesianAxis object for this to work.
2) If you want the x-axis to have a time value whereas the y-axis to have a double value then you need to use TimeTuple as mentioned in the example quoted by you. You might also have to configure the xAxes object in the config to be a TimeAxis object.
3) If you want double (or int) value to be plotted along y-axis against string labels on the x-axis then you need to use Wrappers provided in the ChartJs.Blazor.ChartJS.Common.Wrappers namespace and configure the xAxes to a CategoryAxis object in the config. An example of this is provided in the code hosted on https://github.com/LearnC0de/BlazorAppLineChart/blob/master/BlazorAppLineChart/BlazorAppLineChart/Pages/LineChart.razor
Related
I am using amCharts4 and is able to plot a vertical line on my Gantt chart representing the current date time as described in the following : Draw a vertical line representing the current date in amcharts gantt chart?. However, how do I make the vertical line move every sec on the chart based on the current time? Here is the code :
var range = dateAxis.axisRanges.create();
range.date = new Date("2020-10-29 07:04:56");
range.grid.stroke = am4core.color("red");
range.grid.strokeWidth = 2;
range.grid.strokeOpacity = 1;
You can add a setInterval that runs every second to update the date on your range, like this:
// First, create your range marker
var range = dateAxis.axisRanges.create();
range.grid.stroke = am4core.color("red");
range.grid.strokeWidth = 2;
range.grid.strokeOpacity = 1;
range.date = new Date();
// Then, update the position of your range marker every second
range.date = new Date(2018, 0, 1, 8, 0, 0, 0);
var timeout = window.setInterval(() => {
range.date = new Date(range.date.getTime() + 1000);
}, 1000);
chart.events.on('beforedisposed', () => {
clearTimeout(timeout);
});
Here is an example
UPDATE
One thing you want to do with the timeout is to also clear it when you no longer need it--- for example, when you dispose the chart or the marker.
I have updated the code above to clear it before the chart is disposed.
I have been trying add custom inline styles for the cells where double underline is applied. My plan was to get the cell where the double underline is aplied and using its indexes find the currosponding td and then aplly custom style/tag.
Currently i am able to find the row and column indexes but if at all i find the row and colum index how can i find the currosponding td in the html string ?
Is there any way to find td using the row and column index ?
Is there any way to get this done, please let me know.
To apply a double underline border style to a cell / range by using the setBorder method with the LineStyle double and the borderBottom method
For example, to set a double underline to the cell A1:
window.onload = function (dashboard) {
// Initialize the Spread component with the following line:
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var activeSheet = spread.getActiveSheet();
// create line border
var border = new GC.Spread.Sheets.LineBorder();
border.color = "red";
// line style = double
border.style = GC.Spread.Sheets.LineStyle.double;
var cell = activeSheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport);
// setting the border to the bottom
cell.borderBottom(border);
};
If you have any other questions feel free to reach out to the SpreadJS Support Team here: Submit a ticket
Best, Mackenzie Albitz | GrapeCity Technical Engagement Engineer
I've looked here:
https://www.amcharts.com/docs/v4/reference/xycursor/
and tried this
chart.cursor.fontSize = "14";
chart.cursor.fill = am4core.color("#ff0000");
chart.cursor.fontFamily = "verdana";
To style the (default white on black) element when the xycursor touches the X/Y axis (don't know what the correct name for this element is, hope you know which one I mean)
I would like to set the font size and family. Tried to set the color to red to see if it has to be set via the fill property, but also that doesn't work.
Created the cursor like this:
chart.cursor = new am4charts.XYCursor();
chart.cursor.xAxis = axis;
You have to set the tooltip properties inside the axis objects directly, as mentioned in the documentation. For example, to change the font, size and color in the category axis tooltip, modify the tooltip's label object:
categoryAxis.tooltip.getFillFromObject = false;
categoryAxis.tooltip.label.fill = "#ff0000"
categoryAxis.tooltip.label.fontFamily = "Courier New"
categoryAxis.tooltip.label.fontSize = 15;
Demo
I'm new to programming and now I want to give custom label on categoryAxies in line chart.
But that label should be regular(like 0,50,100,150).
This is my format of data.
59.0472,0.0318
69.071,0.0271
72.0913,0.0271
81.0674,0.0334
81.0734,0.0382
83.0596,0.0717
83.0894,0.0605
85.0817,0.035
85.1053,0.0287
86.0675,0.0318
87.1001,0.0287
90.6657,0.0382
I want x-axis as 0, 50 , 60, etc.
Also i have mentioned the category axis code in below
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = false;
categoryAxis.autoGridCount =false;
categoryAxis.dashLength = 1;
categoryAxis.gridCount = 6;
categoryAxis.gridAlpha = 0.15;
categoryAxis.minorGridEnabled = true;
categoryAxis.axisColor = "#DADADA";
If you X axis should be numeric, than I would recommend you using XY chart instead of Serial, for example: http://www.amcharts.com/javascript-charts/scatter/
Can anyone tell me the attribute to set to label the units on a LinePlot in ReportLab? Also, if you know how to set a title, that would be ultimately super helpful.
drawing = Drawing(50,50)
data = [(tuple(zip(matfile['chan'].item([6],matfile['chan'].item()[7].item()[0])))]
lp = LinePlot()
lp.data = data
lp.????? = (str(matfile['chan'].item()[3]), str(matfile['chan'].item()[2]))
drawing.add(lp)
elements.append(drawing)
This is actually going to be inside a loop - I load a .mat file and there's about 50 channels, and I am going to plot almost all of them. Separately. But first I need to get a handle on assigning the labels (title text, which will be the same as the channel, then the units for the axes...) X Axis label should always be 'Seconds', Y axis label will vary... sometimes a %, sometimes a pressure or temperature or speed, etc.
I have no idea how to do THAT, but I ended up using framing tables and I cobbled together something.I did not succeed in rotating the text for the y axis label.
for channel in channels:
drawing = Drawing(0,0)
data = [(tuple(zip(matfile[channel].item()[6],matfile[channel].item()[7].item()[0])))]
lp = LinePlot()
lp.data = data
lp.width = 6*inch
lp.height = 3.25*inch
stylesheet = getSampleStyleSheet()
y_label = Paragraph(str(matfile[channel].item()[2]), stylesheet['Normal'])
drawing.add(lp)
plot_table = [['',str(channel)],
[y_label, drawing],
['',matfile[channel].item()[3]]]
t_framing_table = Table(plot_table)
t_framing_table._argH[1] = lp.height + .5*inch
t_framing_table._argW[1] = lp.width
elements.append(t_framing_table)
if break_page:
elements.append(PageBreak())
break_page = False
else:
break_page = True