Windows UWP SFChart - Column or Bar chart plot color based on value? - syncfusion

Is it possible to set the color of the bar based on the value, for example say my min was 0 and max was 10, if my value is between 0 and 3 color the bar green, if its between 3 and 7 colour it blue, and if its between 7 and 10 color it yellow.

Yes. It is possible to set the color based on the value. We can able to achieve your requirement by customizing the individual bar/column template color by CustomTemplate property as per the below code snippet.
Code Snippet [XAML]:
<Grid.Resources>
<local:ColorConverter x:Key="conv1"/>
<DataTemplate x:Key="columnTemplate1">
<Canvas>
<Rectangle Canvas.Left="{Binding RectX}" Canvas.Top="{Binding RectY}" Height="{Binding Height}"
Width="{Binding Width}" Stretch="Fill"
Fill="{Binding Converter={StaticResource conv1}}"></Rectangle>
</Canvas>
</DataTemplate>
</Grid.Resources>
<Grid.DataContext>
<local:TestingValuesCollection/>
</Grid.DataContext>
<syncfusion:SfChart x:Name="chart" >
<syncfusion:SfChart.SecondaryAxis>
<syncfusion:NumericalAxis Minimum="0" Maximum="10"/>
</syncfusion:SfChart.SecondaryAxis>
<syncfusion:ColumnSeries x:Name="series1" ItemsSource = "{Binding TestingModel}" XBindingPath = "X"
CustomTemplate="{StaticResource columnTemplate1}" YBindingPath = "Y">
</syncfusion:ColumnSeries>
</syncfusion:SfChart>
Code Snippet [C#]:
public class ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
ColumnSegment segment = value as ColumnSegment;
//First region value declaration.
DoubleRange firstRegion = new DoubleRange(0, 3);
SolidColorBrush firstRegionBrush = new SolidColorBrush(Colors.Green);
//Second region value declaration.
DoubleRange secondRegion = new DoubleRange(3, 7);
SolidColorBrush secondRegionBrush = new SolidColorBrush(Colors.Blue);
//Third region value declaration.
DoubleRange thirdRegion = new DoubleRange(7, 10);
SolidColorBrush thirdRegionBrush = new SolidColorBrush(Colors.Yellow);
if (segment.YData >= firstRegion.Start && segment.YData <= firstRegion.End)
return firstRegionBrush;
else if (segment.YData >= secondRegion.Start && segment.YData <= secondRegion.End)
return secondRegionBrush;
else if (segment.YData >= thirdRegion.Start && segment.YData <= thirdRegion.End)
return thirdRegionBrush;
return segment.Interior;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
We can able to add more region in converter and return any color to the bar/column.
We have done this code based on y-axis value. If your requirement is based on x-axis value means check segment.XData instead of checking segment.YData in converter.

Related

Display float value in input field of dat.gui in three js

I added inseam inch value 31.8 as default value but it show 32. This is my code.
var params = {
Inseam: 0,
inseamarea:31.8,
};
var gui = new GUI();
var folder = gui.addFolder( 'Morph Targets' );
folder.add( params, 'Inseam', -1, 1 ).step( 0.1 ).onChange( function ( value ) {
params.inseamarea = 31.8 +(1.4 * value);
} );
folder.add(params, "inseamarea", 31.8).name("Inseam Inch ").listen();
I want value in float but it show in integer.
I found a link which i followed. https://jsfiddle.net/prisoner849/514d4kmy/
and this is my fiddel link where i added my code in same place. https://jsfiddle.net/kwdphca0/
You should simply use step(), e.g. :
folder.add(params, "inseamarea", 31.8).step(0.1).name("Inseam Inch ").listen();
https://github.com/dataarts/dat.gui/blob/master/API.md#numbercontroller--datcontrollerscontroller :
if minimum and maximum specified increment is 1% of the
difference otherwise stepValue is 1
EDIT : If you want to disable this controller :
let ctrl = folder.add(params, "inseamarea", 31.8).step(0.1).name("Inseam Inch ").listen();
ctrl.domElement.style.pointerEvents = "none";

Converting short colorVal = CellStyle.getBottomBorderColor () to RGB value while using Apache POI Java library

I am reading Excel sheet using Apache POI and writing it to a PDF using iText library.This has been achieved successfully but I am getting default black border for every cell that I write to PDF. So I need to get the cell border color using Apache POI which can be achieved using CellStyle class method getBottomBorderColor() which returns a short value.However I need a way to convert this value to RGB value so that while writing cell to PDF I can apply that RGB color value to the cell border.
The short value from CellStyle.getBottomBorderColor is an index of the color in the color palette of the workbook. This is an olld approach for storing colors from the old binary *.xls Excel format. So in apache poi there is only HSSFPalette which only should be used in HSSF and not more be used in XSSF.
In newer *.xlsx Excel formats, the color will either be stored directly as hex value or as reference to a theme color. So for XSSF there is XSSFCellStyle.getBottomBorderXSSFColor to get that color directly and not via index.
So unfortunately we have to differ both aproaches dependent on the kind of Excel workbook.
Example:
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import java.io.FileInputStream;
class ExcelCellBorderColor{
public static void main(String[] args) throws Exception {
Workbook wb = WorkbookFactory.create(new FileInputStream("ExcelCellBorderColor.xlsx"));
//Workbook wb = WorkbookFactory.create(new FileInputStream("ExcelCellBorderColor.xls"));
String strrgb;
Sheet sheet = wb.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
CellStyle style = cell.getCellStyle();
if (style instanceof XSSFCellStyle) {
XSSFColor xssfcolor = ((XSSFCellStyle)style).getBottomBorderXSSFColor();
if (xssfcolor != null) {
byte[] brgb = xssfcolor .getRGB();
strrgb = "R:"+String.format("%02X", brgb[0])+",G:"+String.format("%02X", brgb[1])+",B:"+String.format("%02X", brgb[2]);
System.out.println("Cell " + cell.getAddress() + " has border bottom color: " + strrgb);
}
} else if (style instanceof HSSFCellStyle) {
short colorindex = ((HSSFCellStyle)style).getBottomBorderColor();
HSSFPalette palette = ((HSSFWorkbook)wb).getCustomPalette();
HSSFColor hssfcolor = palette.getColor(colorindex);
if (hssfcolor != null) {
short[] srgb = hssfcolor.getTriplet();
strrgb = "R:"+String.format("%02X", srgb[0])+",G:"+String.format("%02X", srgb[1])+",B:"+String.format("%02X", srgb[2]);
System.out.println("Cell " + cell.getAddress() + " has border bottom color index: " + colorindex + ". This is " + strrgb);
}
}
}
}
wb.close();
}
}
you can archive this by using this color class
CTScRgbColor scrgb = (CTScRgbColor)ch;
int r = scrgb.getR();
int g = scrgb.getG();
int b = scrgb.getB();
color = new Color(255 * r / 100000, 255 * g / 100000, 255 * b / 100000);

android-graphview shows wrong graphs with setNumVerticalLabels

i test the android-graphview library and i find this behavior:
I use the latest GraphViewDemos and the first SimpleGraph example. It shows a linegraph with the correct data. (The y-axis values are 1,2,3)
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(2.5, 3.0d) // another frequency
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
, new GraphViewData(5, 3.0d)
});
The max value is three (Sorry i can't post an image) and all other coordinates are correct.
If i add these lines
graphView.getGraphViewStyle().setNumVerticalLabels(5);
graphView.setVerticalLabels( new String[]{"4","3","2","1","0"});
before
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
in the code to change the y-axis, i get a graph where the max-value is not still three, it's four. And all the other coordinates are wrong in the y-values.
Why does the complete graph change and not only the y-axis?
with the line:
graphView.setVerticalLabels( new String[]{"4","3","2","1","0"});
you set static labels to the graph. So the vertical labels (y-values) have no link to the data anymore.
This line is for dynamic labels. You can modify the count of the labels that will be generated.
graphView.getGraphViewStyle().setNumVerticalLabels(5);
But you are using static labels, so the line doesn't make sense.
http://android-graphview.org/
Visit this page and scroll to the Custom Label Formatter part of the tutorial.
GraphView graphView = new LineGraphView(this, "example");
graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
#Override
public String formatLabel(double value, boolean isValueX) {
if (isValueX) {
if (value < 5) {
return "small";
} else if (value < 15) {
return "middle";
} else {
return "big";
}
}
return null; // let graphview generate Y-axis label for us
}
});
Basically you will have to map the actual y value with the static Vertical Label you have provided

Dynamically Generated Telerik MVC3 Grid - Add Checkboxes

I have a grid that is dynamically generated based on search criteria. I render the grid in a partial view using Ajax. That all works fine.
I now need to add a checkbox column as the first column.
Also, how do I get filtering, sorting paging etc. to work now since it is in a partial view.
When i click on a header to sort I get a Page not found error and the filter Icon doesnt do anything.
And one more thing. When I try to add a GridCommandColumnSettings to the grid I get the error
"Invalid initializer member declarator"
Code is below for the gridcolumnsettings
public GridColumnSettings[] NewColumns(DataTable fullDT)
{
GridColumnSettings[] newColumns = new GridColumnSettings[fullDT.Columns.Count];
for (int i = 0; i < fullDT.Columns.Count; i++)
{
// set the visibility property for the DeliveryID
bool boolDeliveryID;
if (fullDT.Columns[i].ColumnName == "DeliveryID")
boolDeliveryID = false;
else
boolDeliveryID = true;
newColumns[i] = new GridColumnSettings
{
new GridCommandColumnSettings
{
Commands =
{
new GridEditActionCommand(),
new GridDeleteActionCommand()
},
Width = "200px",
Title = "Commands"
},
Member = fullDT.Columns[i].ColumnName,
Title = fullDT.Columns[i].ColumnName,
Visible = boolDeliveryID,
Filterable = true,
Sortable = true
};
}
return newColumns;
}
Any suggestions would be appreciated.
Thanks
I edited my post to add my partial for the Grid
Here is my partial for the grid
#(Html.Telerik().Grid<System.Data.DataRow>(Model.Data.Rows.Cast<System.Data.DataRow>())
.Name("Grid")
.Columns(columns =>
{
columns.LoadSettings(Model.Columns as IEnumerable<GridColumnSettings>);
})
.DataBinding(dataBinding => dataBinding.Ajax().Select("_DeliveryManagerCustomBinding", "Deliveries"))
.EnableCustomBinding(true)
.Resizable(resize => resize.Columns(true))
)
I don't add columns this way when I use the Telerik Grid control, but looking at what you're doing I would hazard a guess to say you will need to do something like the following:
increase the size of the newColumns array by 1 (because we're going to add in the checkbox column):
GridColumnSettings[] newColumns = new GridColumnSettings[fullDT.Columns.Count + 1];
if you want it at the beginning you will need to do the following before your for-loop:
GridColumnSettings s = new GridColumnSettings() {
ClientTemplate("<input type=\"checkbox\" name=\"checkeditems\" value=\"some value\" />")
Title("title goes in here")
};
Then you will add it into your array:
newColumns[0] = s;
and then increase the start index for your for-loop to 1:
for (int i = 1; i < fullDT.Columns.Count; i++)
the checkbox column will go at the beginning

How to disable Fusioncharts legend area?

How can I disable/remove the legend area when using FusionCharts? I'll be using a very small chart, so the legend area is not necessary.
Adding a showLegend='0' tag should disable it. Use it like this:
<chart showLegend='0'...>
Check out FusionCharts Legend API for more help on legends.
How to set Show legend property to my Fusion Graph.My code like this.
public Pie2DChart GetServiceEsclationChart(DataTable BarChartdt, string CaseType)
{
Pie2DChart oChart3 = new Pie2DChart();
// Set properties
oChart3.Background.BgColor = "ffffff";
oChart3.Background.BgAlpha = 50;
oChart3.ChartTitles.Caption = "Case Type Count";
oChart3.ChartTitles.Caption = CaseType;
// oChart.ChartTitles.SubCaption = "2013-2014 Year";
// Set a template
oChart3.Template = new Libero.FusionCharts.Template.OfficeTemplate();
// Set data
oChart3.DataSource = BarChartdt;
oChart3.DataTextField = "Name";
oChart3.DataValueField = "Value";
//Load it into ViewData.
// ViewData["SREsclation"] = oChart3;
return oChart3;
}